简体   繁体   English

Django登录后未重定向到管理站点

[英]Django Not Redirecting to Admin Site after Login

I needed one more login form field to login django admin. 我还需要一个登录表单字段来登录django admin。 I overridden AdminSite.login_form 我覆盖了AdminSite.login_form

CODE:forms.py 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

Then I rendered this from, CODE: views.py 然后我从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}

And I created a template as well in templates/admin/login.html 我也在模板/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>

All is working fine, I can submit login form. 一切正常,我可以提交登录表格。 But I redirects me to the page: 但我将我重定向到页面:

http://example.com/accounts/profile/ http://example.com/accounts/profile/

And I am getting page not found error,but if put http://excample.com/admin in URL it shows me logged in and I can see admin site. 而且我收到页面未找到错误,但是如果将http://excample.com/admin放在URL中,则表明我已登录并且可以看到管理站点。

Basically I am able to login but its not redirecting me to admin page. 基本上,我能够登录,但不能将我重定向到管理页面。

Any fix to this.... 任何修复此问题。

Set settings.LOGIN_REDIRECT_URL to /admin/ : 设置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. 当contrib.auth.login视图没有下一个参数时,登录后重定向请求的URL。

Or you can send next parameter to login view . 或者,您可以将next参数发送到登录视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM