简体   繁体   English

Django LogoutView 不注销但重定向到登录页面

[英]Django LogoutView doesn't logout but redirects to login page

I am new to Django.我是 Django 的新手。 I have this problem that The auth LoginView works perfectly well but the LogoutView doesnt.我有这个问题,auth LoginView 工作得很好,但 LogoutView 没有。

It only redirects to login page.它只重定向到登录页面。

 from django.contrib.auth import views as auth_views  
  
    path('user/login/', auth_views.LoginView.as_view(template_name='login.html'), name='login'),
    path('user/logout/', auth_views.LogoutView.as_view(template_name='logout.html'), name='logout'),

My logout.html file is as follows我的logout.html文件如下

{% extends "base.html" %} {% load crispy_forms_tags %} {% load static %}
{% block content %}
<br />
<div class="container">
  <div class="row">
    <div class="col-sm-9 col-md-9 col-lg-7 mx-auto">
      <div class="card card-signin my-5">
        <div class="card-body">
          <h5 class="card-title text-center"><b>Register</b></h5>
          <form class="form-signin" method="POST">
            {% csrf_token %}
            <fieldset class="form-group">
              <br />
              {{ form|crispy }}
            </fieldset>
            <div class="form-group">
              <button
                class="btn btn-lg btn-primary btn-block text-uppercase"
                type="submit"
              >
                Sign Up</button
              ><br /><br />
            </div>
            <small
              ><p class="text-center">
                Already Registered!
                <a href="{% url 'login' %}"><b>Login Now!</b></a>
              </p></small
            >
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock content %}

Please does anyone know why this could be happening.请问有谁知道为什么会发生这种情况。 Is it possible that the default auth LoginView could be working and the default auth Logoutview is not working.是否有可能默认的身份验证 LoginView 可以正常工作,而默认的身份验证 Logoutview 不能正常工作。 Or am I doing something wrong?.还是我做错了什么?

Thank you for your answers.谢谢您的回答。

send your html detail of logout view.发送注销视图的 html 详细信息。 you are doing it right but may be you are not giving instructions to your logout view.您做得对,但可能是您没有向注销视图提供说明。

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

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