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