2015-05-27 41 views
1

我:如何處理我的login_required網址?

鏈接網址:

from django.conf.urls import include, url 
from django.contrib import admin 

urlpatterns = [ 
    url(r'^admin/', include(admin.site.urls)), 
    url(r'^$', 
     include('distributors.urls', namespace='distributors')), 
    url(r'^accounts/', include('allauth.urls')), 
] 

應用網址:

url(r'^$', views.Index.as_view(), name='index'), 
url(r'^links/$', login_required(views.LinkListView.as_view(), name='links'), 
在我的HTML

我有href="{% url 'distributors:index' %}"href="{% url 'distributors:links' %}"

瀏覽:

class Index(TemplateView): 
    template_name = "distributors/index.html" 


class LinkListView(ListView): 
    model = Link 
    template_name = "distributors/links.html" 
    context_object_name = 'links' 

當我嘗試進入http://127.0.0.1:8000/我看到The included urlconf 'linker.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

任何想法如何解決這個問題?

+0

分享你的linker.urls內容。 – moonstruck

回答

2

首先刪除美元符號時,包括其他網址模式。

url(r'^', 
    include('distributors.urls', namespace='distributors')), 

其次,你正在使用login_required缺少一個右括號。

url(r'^links/$', login_required(views.LinkListView.as_view()), name='links'), 
+0

仍然是同樣的錯誤。我發現使用login_required ulrs和反轉它們有一些問題,但我仍然無法處理它。 – pythad

+0

您正在使用'login_required' - 我更新了我的答案。 – Alasdair

+0

啊,多麼愚蠢的錯誤......謝謝! – pythad