简体   繁体   中英

Syntax Error in the urls.py in Django

I am trying to add a few urls in my urls.py.

urls.py

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'Permissions.views.home', name='home'),
    # url(r'^Permissions/', include('Permissions.foo.urls')),
     #url(r'^Permissions$', include('Permissions.Authenication.urls')),
     url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
     url(r'^admin/', include(admin.site.urls)),
     url(r'^$',RedirectView.as_view(url='/welcome/'),
)

urlpatterns += patterns('',
     url(r'^register/$', 'drinker.views.DrinkerRegistration',name='DrinkerRegistration'),
     url(r'^welcome/$','drinker.views.DrinkerWelcome',name='DrinkerWelcome'),
     url(r'^home/(?P<userpk>[^/]+)/$','drinker.views.DrinkerHome',  name='DrinkerHome'),     
)

Error:

Traceback:
File "/Users/cnnlakshmen_2000/Projects/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/Users/cnnlakshmen_2000/Projects/env/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/Users/cnnlakshmen_2000/Projects/env/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/cnnlakshmen_2000/Projects/env/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/Users/cnnlakshmen_2000/Projects/env/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: SyntaxError at /
Exception Value: invalid syntax (urls.py, line 17)

Not sure where the error is... Need some help...

You're missing a parenthesis and have an extra comma:

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'Permissions.views.home', name='home'),
    # url(r'^Permissions/', include('Permissions.foo.urls')),
    # url(r'^Permissions$', include('Permissions.Authenication.urls')),

    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$', RedirectView.as_view(url='/welcome/')) #Error was here
)

You have another trailing comma in your second half:

urlpatterns += patterns('',
    url(r'^register/$', 'drinker.views.DrinkerRegistration',name='DrinkerRegistration'),
    url(r'^welcome/$','drinker.views.DrinkerWelcome',name='DrinkerWelcome'),
    url(r'^home/(?P<userpk>[^/]+)/$','drinker.views.DrinkerHome', name='DrinkerHome') # Comma was here     
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM