0
我使用djnago HttpResponseRedirect
在登錄後返回上一頁。問題是,我給了一個錯誤的重定向網址(next
網址和當前網址的組合)HttpResponseRedirect將傳遞的URL附加到當前的URL
假設我已經從「mysite.com/home」登錄並且登錄頁面的網址是「mysite.com/login」我想返回到「mysite.com/home」,但重定向網址是mysite.com/login/?next=/home/。
我在做什麼錯了?
這裏是我的view
,負責登錄:
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# next is "/home/" and that is exactly what I expect
return HttpResponseRedirect(request.GET.get('next', reverse('products.views.show_homePage')))
顯示我們的'request.POST.get( '下一步')'之前調用重定向的精確值。 – mariodev
由於'request.POST'原因導致「next = a url」位於查詢字符串中,但我仍然犯了一個錯誤,但該值仍與我在代碼(註釋部分)中提到的相同。 –
此外,我改變了表單動作url在客戶端(javascript)的絕對路徑,並解決了這個問題,但我不知道什麼是錯的 –