'url'需要非空的第一个参数.Django 1.5中的语法发生了变化,请参阅文档

Imo*_*oum 1 authentication django login

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

r'^login/$', 'django.contrib.auth.views.login',  {'template_name': 'login.html'}),
Run Code Online (Sandbox Code Playgroud)

这是我的模板

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>
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

bru*_*ers 9

您需要围绕视图名称的引号:

<form action="{% url "django.contrib.auth.views.login" %}" method="post">
Run Code Online (Sandbox Code Playgroud)