0
我試圖通過轉到login-redirect
頁面來登錄用戶,然後頁面重定向到用戶個人資料頁面。我明白,這不是第一次問這個問題,但我已經嘗試了所有其他答案,我不知道爲什麼這不適合我。Django重定向到kwargs的其他應用程序中的網址
urls.py
urlpatterns = [
url(r'^login/$', auth_views.login, {'template_name': 'login.html'}, name="login"),
url(r'^login/redirect/$', account_redirect, name="account-redirect"),
url(r'^logout/$', auth_views.logout, {'next_page': 'home'}, name="logout"),
url(r'^stores/', include('stores.urls', namespace='store_app'))
]
views.py
def account_redirect(request):
# tried both to see if it would help...
# return HttpResponseRedirect(reverse('store_app:account-landing', kwargs= {"pk":request.user.pk,"name":request.user.vendor.name}))
return redirect('store_app:account-landing', pk=request.user.pk, name=slugify(request.user.vendor.name))
存儲/ urls.py
urlpatterns = [
url(r'^account/(?P<pk>\d+)/(?P<name>\w+)/$', AccountLanding.as_view(), name="account-landing"),
]
基於SERV其他相關問題的答案,這應該很好,但事實並非如此。之後,我登錄,並獲得login/redirect/
我得到以下錯誤:
Reverse for 'account-landing' with arguments '()' and keyword arguments '{'pk': 1, 'name': u'Fake Company'}' not found. 1 pattern(s) tried: [u'stores/account/(?P<pk>\\d+)/(?P<name>\\w+)/$']
我不明白,它試圖正確的模式,並有正確的論點?那爲什麼它不起作用?
現在很好用,不知道爲什麼我沒有想到這一點。是的,我用的線實際上沒有註釋掉。謝謝! – thefoxrocks
@thefoxrocks - 不用擔心,盡情享受吧! – Sayse