gpt4 book ai didi

python - django 出现 urls.py 语法错误,我不知道为什么

转载 作者:行者123 更新时间:2023-11-30 23:01:58 24 4
gpt4 key购买 nike

这是回溯...

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

最佳答案

您错过了这一行的右括号

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

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

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

关于python - django 出现 urls.py 语法错误,我不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34704437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com