【问题标题】:'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs'url' 需要一个非空的第一个参数。 Django 1.5 中的语法发生了变化,请参阅文档
【发布时间】:2013-04-05 04:33:43
【问题描述】:

我正在尝试使用 django.contrib.auth 登录,但似乎这在 Django 1.5 中不起作用 这是 urls.py

r'^login/$', 'django.contrib.auth.views.login',  {'template_name': 'login.html'}),

这是我的模板

1   {% extends "website/base.html" %}
2   
3   {% block content %}
4   
5   {% if form.errors %}
6   <p>Authentication error</p>
7   {% endif %}
8   
9   <form action="{% url django.contrib.auth.views.login %}" method="post">
10    {% for field in form %}
11    <p>
12      {{ field.label_tag }}: {{ field }}
13      {{ field.errors }}
14    </p>
15    {% endfor %}
16    <p><input type="submit" value="Login" /></p>
17    <input type="hidden" name="next" value="{{ next }}" />
18  </form>

我该如何解决??

【问题讨论】:

    标签: django authentication login


    【解决方案1】:

    您需要在视图名称周围加上引号:

    <form action="{% url "django.contrib.auth.views.login" %}" method="post">
    

    【讨论】:

      猜你喜欢
      • 2013-01-30
      • 2013-02-22
      • 2023-03-13
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      相关资源
      最近更新 更多