gpt4 book ai didi

python - Django 登录后不重定向到管理站点

转载 作者:太空宇宙 更新时间:2023-11-03 18:40:43 25 4
gpt4 key购买 nike

我还需要一个登录表单字段来登录 django admin。我重写了 AdminSite.login_form

代码: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

然后我渲染了这个,代码: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}

我也在 templates/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 中,它显示我已登录,并且我可以看到管理站点。

基本上我可以登录,但它不会将我重定向到管理页面。

对此的任何修复....

最佳答案

设置settings.LOGIN_REDIRECT_URL/admin/:

Default: '/accounts/profile/'

The URL where requests are redirected after login when the contrib.auth.login view gets no next parameter.

或者您可以将next参数发送到login view .

关于python - Django 登录后不重定向到管理站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20561084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com