2016-01-10 79 views
1

這裏是回溯...的Django得到一個urls.py語法錯誤,我不知道爲什麼

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) 

我幾乎可以肯定有我的語法沒有錯誤。我認爲這是因爲一些命名空間問題而發生的,但我看不到在哪裏。

我有我的基本URL是這樣的...

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行...

存在另一個網址的線86 .py在這種情況下正在使用,但沒有錯誤,據我所知,我從來沒有碰過它...

這裏是第85-91行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'), 
) 
+0

錯誤在第86行(或者通常在行之前)。那麼你能告訴我們這些線嗎?這是一個* Syntax *錯誤,純粹是一個Python問題,與Django相關。 – RemcoGerlich

回答

3

你已經錯過了這條線

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

一個右括號您已經關閉了include()電話,但你需要一個第二)關閉url()。它應該是:

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

哇謝謝,我現在覺得啞巴了100倍 – deltaskelta

相關問題