0
这是我第一次用用户身份验证编写自定义视图。因为我真的不知道我应该注意什么或者我应该注意什么,所以我被困在几个小时之后,因为我使用@login_required修饰器。这里是我的views.py:使用@login_required装饰器
from django.shortcuts import render
from programm.models import *
from django.contrib.auth.decorators import login_required
def index(request):
return render(request, 'index.html')
@login_required
def liste(request):
return render(request, 'liste.html', {'lObj': learningObjective.objects.all()})
这是我的应用程序urls.py:
from django.conf.urls import patterns, url
from programm import views
from django.conf import settings
urlpatterns = patterns('',
url(r'^$', views.index, name = 'index'),
url(r'^liste.html$', views.liste, name = 'liste'),
)
这是login.html的模板:
{% block body %}
<header>
<h1>Login Page</h1>
</header>
<section>
{% if form.errors %}
<p>Your username and password didn't match, please try again.</p>
{% endif %}
<form method="post" action=".">
{% csrf_token %}
<p>
<label for="id_username">Username:</label>
{{ form.username }}
</p>
<p>
<label for="id_password">Password:</label>
{{ form.password }}
</p>
{% if next %}
<input type="hidden" name="next" value="{{ next }}" />
{% else %}
<input type="hidden" name="next" value="/programm/liste.html" />
{% endif %}
<input type="submit" value="login" />
</form> </section> {% endblock %}
</section>
{% endblock %}
你们能告诉我我必须注意什么以及我必须补充什么吗?我没有找到我正确理解指南:/错误消息我目前得到的是以下几点:
TemplateDoesNotExist at /login/
registration/login.html
Request Method: GET
Request URL: http://10.0.3.107:8000/login/?next=/programm/liste.html
Django Version: 1.6.1
Exception Type: TemplateDoesNotExist
Exception Value:
registration/login.html
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/loader.py in find_template, line 131
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/ubuntu/NachweisProj/ANachweis',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Server time: Wed, 19 Feb 2014 14:08:12 +0000
我没有看到任何代码来做实际的登录过程。 – Aldarund
我认为使用@login_required装饰器我调用了一个自定义的django登录视图Oo –