2013-02-13 57 views
0

首先,我已經閱讀了這個django username in url, instead of id它的幫助,但並沒有解決我的問題。如果我能幫上忙,我不想在views.py中寫任何代碼。將用戶名傳遞給Generic DetailView時出錯 - django 1.4.3

我在urls.py下試過的東西。注:在這兩種情況下,我得到name 'username' is not defined

urlpatterns = patterns('', 
    url(r'^(?P<username>[\[email protected]+-]+)/$', 
     login_required(
      DetailView.as_view(
       model=User, 
       username=username, 
       template_name='account/user_detail.html'), 
      login_url='/accounts/login/' 
     ) 
    ), 
) 
urlpatterns = patterns('', 
    url(r'^(?P<username>[\[email protected]+-]+)/$', 
     login_required(
      DetailView.as_view(
       model=User, 
       queryset=User.objects.get(username=username), 
       template_name='account/user_detail.html'), 
      login_url='/accounts/login/' 
     ) 
    ), 
) 

回答

1

你不能做這種URL配置動態過濾的。子類DetailView並覆蓋get_queryset以過濾self.kwargs['username']

相關問題