包括base.html中的登录表单

时间:2018-05-27 19:34:42

标签: python django

我正在使用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文件

    <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>

但是我的登录表单根本不起作用,它只是在按下提交后重新加载页面  有什么建议可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

您还没有告诉表单在哪里提交;您的HTML 2018-05-26T21:33:46 2018-05-26T**23**:33:46+02:00[Europe/Paris] 2018-05-26T**14**:33:46-07:00[America/Los_Angeles] 代码需要<form>属性以及您的登录视图的网址。

相关问题