我是django的新手,尽管我有使用python的经验。我正在学习django,但是当我尝试使用包含的登录系统时,我收到以下错误:
Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/lib/python2.7/site-packages/django/contrib/admin/templates/registration/login.html (File does not exist)
/usr/lib/python2.7/site-packages/django/contrib/auth/templates/registration/login.html (File does not exist)
来自views.py的相关代码:
@login_required
def userPage(request):
return HttpResponse("Hello User!")
我在Fedora 20上使用django 1.6.1和python 2.7.5。我已经尝试重新安装django。在错误消息的文件夹中是其他模板。我该如何解决这个问题?
答案 0 :(得分:18)
您需要提供网址(project / urls.py)
from django.contrib.auth.views import login
from django.contrib.auth.views import logout
url(
regex=r'^login/$',
view=login,
kwargs={'template_name': 'login.html'},
name='login'
),
url(
regex=r'^logout/$',
view=logout,
kwargs={'next_page': '/'},
name='logout'
),
和模板login.html
(类似的东西)
<form action="{% url 'login' %}" method="post" accept-charset="utf-8">
{% csrf_token %}
{% for field in form %}
<label>{{ field.label }}</label>
{% if field.errors %}
{{ field.errors }}
{% endif %}
{{ field }}
{% endfor %}
<input type="hidden" name="next" value="{{ next }}" />
<input class="button small" type="submit" value="Submit"/>
</form>
答案 1 :(得分:5)