0

我正在尝试在我的 urls.py 中添加一些 url。

网址.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'),     
)

错误:

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)

不知道错误在哪里......需要一些帮助......

4

1 回答 1

6

您缺少括号并有一个额外的逗号:

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
)

你的后半部分还有一个逗号:

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     
)
于 2012-08-31T14:00:35.687 回答