0

urls.py にいくつかの URL を追加しようとしています。

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'),     
)

エラー:

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 に答える