當用戶登錄到Django應用程序時,如何更改登錄後顯示的頁面的URL? 我目前有以下幾種觀點:如何更改我在Django中重定向的位置的固定鏈接?
def users_login(request):
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
return HttpResponseRedirect("/start/")
我指出應用程序應該重定向到domain.com/start/,但不幸的是,事實並非如此。它會轉到domain/login /,它是登錄表單的action屬性中的位置。
當我有我的看法如下代碼:
return redirect('http://www.google.com/')
我得到一個錯誤。我不明白爲什麼。它只發生在形式上。用戶提交表單後,即使相應的視圖有重定向到靜態頁面,該URL仍停留在操作屬性的URL處。
你確定它沒有?我相信它首先重定向到「/ start /」,然後是「domain/login /」。用Firebug進行檢查。 – DrTyrsa
你好,它不會重定向到/開始/然後到域/登錄/。 – egidra