2012-09-29 281 views
1

看到以下語法錯誤,但urls.py文件似乎是正確的。我錯過了什麼?無法識別Django錯誤

SyntaxError at /admin/ 
invalid syntax (urls.py, line 6) 
Request Method: GET 
Request URL: http://127.0.0.1:8000/admin/ 
Django Version: 1.4.1 
Exception Type: SyntaxError 
Exception Value:  
invalid syntax (urls.py, line 6) 
Exception Location: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 35 
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python 
Python Version: 2.7.2 

這裏的urls.py:

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

from django.contrib import admin 
admin.autodiscover() 

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

...

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

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

回答

3

你缺少一個逗號:

urlpatterns = patterns('', 
    url(r'^create/$', views.create, name='ev_create')  # <-- comma missing 
    url(r'^tonight/$', views.tonight, name='ev_tonight'), 
) 

注意,這是在第5行你的urls.py模塊,但Python只能發現當它在你的url(...)調用後遇到不適合的東西時,它在第6行。