django得到urls.py语法错误,我不知道为什么

时间:2016-01-10 10:38:17

标签: python django

这是追溯......

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)

我几乎可以肯定我的语法没有错误。我认为它正在发生,因为一些命名空间问题,但我无法看到。

我有这样的基本网址......

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

然后我的论坛网址就像这样......

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

然后在这样的模板中调用它......

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

我认为它与这两个命名空间有关,但我还没有能够确定它。有什么想法吗?

编辑:

问题是urls.py中没有第86行跟踪,只有19行......

在这个实例中使用了另一个urls.py中的第86行,但据我所知,没有任何错误,我从未触及它......

这是urls.py的第85-91行......

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

1 个答案:

答案 0 :(得分:3)

你错过了这一行的右括号

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

您已关闭include()来电,但需要第二个)来关闭url()。它应该是:

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