Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^events/', include('events.urls')),
)

and here is my events.urls:

from django.conf.urls.defaults import *
from events import views


urlpatterns = patterns('',
    url(r'^tonight/$', views.tonight, name='ev_tonight'),
)

I am getting the following error after running the server:

Exception Type:     SyntaxError
Exception Value:    

invalid syntax (urls.py, line 8)

Am I missing something here?

Edit: Attaching the traceball

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/admin

Django Version: 1.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'events')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  89.                     response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
  67.             if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in is_valid_path
  531.         resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  420.     return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/bhavish/startthedark/startthedark/urls.py" in <module>
  8.     (r'^events/', include('events.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
  24.         urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: SyntaxError at /admin
Exception Value: invalid syntax (urls.py, line 8

)

share|improve this question
1  
Nothing wrong with the code. Check for some special symbols in the code file... Or check events.urls for an error ... – Tisho Jul 26 '12 at 12:28
Guess you can remove the quotes surrounding events.urls – Pramod Jul 26 '12 at 12:54
@Pramod, no you can't unless you specifically import the events module. – Hedde Jul 26 '12 at 13:50

2 Answers

up vote 3 down vote accepted

The error being raised is in events/urls.py -- check that file carefully. There may be some extra white space at the end of it that you can't see. (The syntax error is supposedly on line 8, but I don't see 8 lines in what you pasted)

You can also try importing that file directly from a python shell, to see if it parses at all.

share|improve this answer
Thanks for the suggestion of "importing that file directly from a python shell". It worked! An exta '~' while copying the content of urls.py – futurenext110 Jul 26 '12 at 14:24

maybe this line: (r'^admin/', include(admin.site.urls)), should be changed to (parenthesis added): (r'^admin/', include('admin.site.urls')),

share|improve this answer
That would cause a NameError at runtime, not a SyntaxError at import. – Ignacio Vazquez-Abrams Jul 26 '12 at 14:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.