我目前正在研究“ Python崩溃课程”一书中的教程。
本教程介绍如何使用Django创建“学习日志” Webapp。该应用程序的想法是允许用户:1.创建他们已了解的“主题” 2.将“条目”添加到这些主题,描述他们已针对这些主题学习的详细信息
我目前在登录页面上停留并在运行时收到错误消息
http:// localhost:8000 / users / login /
urls.py
from django.conf.urls import url
# Importing the default login view provided by Django
from django.contrib.auth.views import LoginView
from .import views
app_name = 'users'
urlpatterns =[
# Login page
url(r'^login/$', LoginView , {'template_name':'users/login.html'},name = 'login'),
]
login.html
{% extends "learning_logs/base.html" %}
{% block content %}
{% if form.errors %}
<p> Your username and password didn't match.Please try again. </p>
{% endif %}
<form method="post" action="{%url 'users:login' %}">
{%csrf_token %}
{{form.as_p}}
<button name="submit">log in</button>
<input type="hidden" name="next" value="{%url 'learning_logs:index' %}"/>
</form>
{% endblock content %}
base.html
<p>
<a href="{% url 'learning_logs:index' %}">Learning Log</a> -
<a href="{% url 'learning_logs:topics'%}">Topics</a> -
{% if user.is_authenticated %}
Hello,{{user.username}}.
{% else %}
<a href="{% url 'users:login' %}">log in</a>
{% endif %}
</p>
{% block content %}{% endblock content %}
该LoginView
是一个基于类的视图,可以使用.as_view(…)
[Django的DOC]在使用它urls.py
。您可以在中传递template_name
as参数.as_view(…)
:
url(r'^login/$', LoginView.as_view(template_name='users/login.html'), name='login'),
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句