简体   繁体   English

包括base.html中的登录表单

[英]including login form in base.html

I'm using context_processors.py to pass the login form to all of my views, then I can include it in all of my pages 我正在使用context_processors.py将登录表单传递给我的所有视图,然后可以将其包含在我的所有页面中

here are my files 这是我的文件

context_processors.py context_processors.py

from django.contrib.auth.forms import AuthenticationForm


def include_login_form(request):
    login = AuthenticationForm()
    return {'login': login}

base.html base.html文件

    <div class="well well-small" style="width: 220px">
        {% if user.is_authenticated %}
            <img src="{% static 'img/user.png' %}">
            <div id="btns">
            <a href="{% url 'logout' %}"><button class="btn-danger">تسجيل الخروج</button></a>
            </div>
            {% else %}
        <form method="post">
    {% csrf_token %}
    {{ login.as_p }}
            <div id="buttons" align="right">
    <button class ="btn btn-primary" type="submit">تسجيل الدخول</button><br><br>
                </div>
  </form>
                  <a href="{% url 'signup' %}"><button type="button" class="btn btn-warning">
          إنشاء حساب جديد</button></a>
        {% endif %}
    </div>

But my login form is not working at all, It just reloads the page after pressing on submit any suggestions to solve this? 但是我的登录表单根本不起作用,它只是在按下提交任何建议以解决此问题后重新加载页面?

You haven't told the form where to submit to; 您尚未告知表单提交至何处; your HTML <form> tag needs an action attribute with the URL of your login view. 您的HTML <form>标记需要一个带有登录视图URL的action属性。

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

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