Python Django未重定向到下一页
我不知道我的代码发生了什么,一旦未经身份验证的用户尝试访问某个页面并重定向到登录页面,我可以在浏览器中看到下一个参数,但在用户登录后,它会将用户带到默认的登录\重定向\ URL,而不是下一个页面。同样在模板上,next返回none,因此模板似乎没有获得next值,但在url中显示/?next=,提前感谢 url.pyPython Django未重定向到下一页,python,django,Python,Django,我不知道我的代码发生了什么,一旦未经身份验证的用户尝试访问某个页面并重定向到登录页面,我可以在浏览器中看到下一个参数,但在用户登录后,它会将用户带到默认的登录\重定向\ URL,而不是下一个页面。同样在模板上,next返回none,因此模板似乎没有获得next值,但在url中显示/?next=,提前感谢 url.py from django.contrib import admin from django.urls import path, include from django.contrib
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth import views as auth_views
from blog import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.HomeView.as_view(),name="index"),
path('accounts/login/', auth_views.LoginView.as_view(), name='login'),
path('accounts/logout/', auth_views.LogoutView.as_view(next_page='/'), name='logout'),
path('accounts/profile/', views.ProfileView.as_view(), name='profile'),
]
注册/登录.html
{% extends 'app/base.html' %}
{% block link %} id="active" {%endblock%}
{% block content %}
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<div class="jumbotron" id="font">
{% if next %}
{% if user.is_authenticated %}
<h2 class="customtext" align="center">Your account doesn't have access to this page. To proceed,
please login with an account that has access.</h2>
{% else %}
<h2 class="customtext" align="center">Please login.</h2>
{% endif %}
{% else %}
<h2 class="customtext" align="center">Enter your login details.</h2>
{% endif %}
<form action="{% url 'login' %}" method="POST">
{%csrf_token%}
<div class="form-group">
<input type="text" name="username" placeholder="username" class="form-control">
</div>
<div class="form-group">
<input type="password" name="password" placeholder="password" class="form-control">
</div>
<!-- <div align="center"> -->
{% if form.errors %}
<!-- <p style="color: red; font-style: italic;">Your username or email is does not match.</p> -->
{{form.errors}}
{% endif %}
<!-- </div> -->
<div class="loginbtndiv" align="center">
<input type="submit" class="btn btn-warning btn-lg loginbtn" value="LOGIN">
</div>
<input type="hidden" name="next" value="{{ next }}">
</form>
</div>
</div>
<div>
</div>
</div>
{% endblock %}
{%extends'app/base.html%}
{%block link%}id=“活动”{%endblock%}
{%block content%}
{%if next%}
{%if user.u经过身份验证%}
您的帐户无权访问此页面。继续,
请使用具有访问权限的帐户登录。
{%else%}
请登录。
{%endif%}
{%else%}
输入您的登录详细信息。
{%endif%}
{%csrf_令牌%}
{%if form.errors%}
{{form.errors}}
{%endif%}
{%endblock%}
您的视图是否返回next
输入context
数据?next的值是多少?我正在使用内置登录视图。渲染视图时,“下一步”的值为“无”。请从窗体中删除“下一步”的隐藏输入,然后重试。它应该从url读取它