简体   繁体   中英

django getting a urls.py syntax error and I am not sure why

Here is the traceback...

Traceback:
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  119.                 resolver_match = resolver.resolve(request.path_info)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
  366.             for pattern in self.url_patterns:
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  402.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  396.             self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)
File "/home/jeff/Django/langalang/langalang/langalang/urls.py" in <module>
  11.     url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
  33.         urlconf_module = import_module(urlconf_module)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
  37.     __import__(name)

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

I am almost certain there is no error in my syntax. I think it is happening because of some namespacing issues, but I can't see where.

I have my base urls like this...

urlpatterns = patterns('',
    # Examples:

    url(r'^admin-011001/', include(admin.site.urls)),
    url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),
    url(r'^(?P<page_lang>\w+)/forum/', include('djangobb_forum.urls', namespace='djangobb')),

and then my forum urls like this....

urlpatterns = patterns('',

    # Forum
    url('^$', forum_views.index, name='index'),
    url('^(?P<forum_id>\d+)/$', forum_views.show_forum, name='forum'),
    url('^moderate/(?P<forum_id>\d+)/$', forum_views.moderate, name='moderate'),
    url('^search/$', forum_views.search, name='search'),
    url('^misc/$', forum_views.misc, name='misc'),
    url(r'^messages/', include('django_messages.urls', namespace='messages_inbox'),

then it is called in a template like this...

<li id="navpm"><a href="{% url 'messages_inbox' %}">{% trans "PM" %}</a></li> 

I think it has something to do with the two namespaces, but I haven't been able to nail it down. Any ideas?

EDIT:

The problem is that there is no line 86 in the urls.py that is in the traceback, there are only 19 lines...

there is a line 86 in another urls.py that is being used in this instance, but there are no errors there as far as I can see, and I have never touched it...

here is lines 85-91 of that urls.py...

# LOFI Extension
if (forum_settings.LOFI_SUPPORT):
    urlpatterns += patterns('',
        url('^lofi/$', forum_views.index, {'full':False}, name='lofi_index'),
        url('^(?P<forum_id>\d+)/lofi/$', forum_views.show_forum, {'full':False}, name='lofi_forum'),
        url('^topic/(?P<topic_id>\d+)/lofi/$', forum_views.show_topic, {'full':False}, name='lofi_topic'),
)

You have missed a closing parenthesis on this line

url(r'^messages/', include('django_messages.urls', namespace='messages_inbox'),

You have closed the include() call, but you need a second ) to close the url() . It should be:

url(r'^messages/', include('django_messages.urls', namespace='messages_inbox')),

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