1
我需要一個登錄表單域來登錄django admin。我重寫AdminSite.login_formDjango登錄後不重定向到管理站點
CODE:forms.py
from django.contrib.admin.forms import AdminAuthenticationForm
from django import forms
from django.contrib.admin.sites import AdminSite
class ModifiedForm(AdminAuthenticationForm):
auth_fact = forms.CharField(max_length=64,required=False)
AdminSite.login_form = ModifiedForm
然後我渲染這個來自 CODE:views.py
def login_test(request):
if request.method == "POST":
form = ModifiedForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password']
auth_fact= form.cleaned_data['auth_fact']
return render_to_response('admin/login.html',{'form':ModifiedForm}
我在模板創建一個模板,以及/ admin/login.html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Login Page</p>
<div class="row-fluid">
<div class="span12">
<form action="" method="POST">{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<p style="margin-left:7%;"><small style="color: red;">example:product name,mfg date,exp date,batch no.</small></p>
<input style="margin-left:10%" class="btn btn-primary" type="submit" name="release" value="Update Product Details "/>
</form>
</div>
</div>
</body>
</html>
所有工作正常,我可以提交登錄表單。但我重定向我的頁面:
http://example.com/accounts/profile/
而且我越來越找不到網頁的錯誤,但如果把http://excample.com/admin在URL它讓我登錄,我可以看到管理站點。
基本上我可以登錄,但不能將其重定向到管理頁面。
任何修復這個....