【发布时间】:2014-09-02 23:12:20
【问题描述】:
实际上,当我使用用户名注册时,它会重定向到注册完成页面。但是当我使用该用户名登录时,它会引发表单错误。因此,当我使用创建的用户名登录时,它会显示
“您的用户名和密码不匹配,请重试”
(我写它是为了在 login.html 中显示 form.errors)
login.html
{% extends "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 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
registration.html
<html>
<head>
<title>Register</title>
</head>
<body>
<h2>Register</h2>
<form action="/accounts/register/" method="POST">{% csrf_token %}
<table>
{{form.as_table}}
</table>
<p>
<input type="submit" value="Submit">
</p>
</form>
</body>
</html>
urls.py
enter code here
from django.conf.urls import patterns, include, url
from frm.views import main,forum,thread
from frm.views import reply,new_thread,profile,post
from django.conf import settings
from django.contrib import admin
from django.conf.urls import *
from django.contrib.auth.views import login
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$',main),
url(r'^forum/(?P<pk>\w+)/$',forum ),
url(r'^thread/(?P<pk>\w+)/$',thread ),
url(r'^post/(new_thread|reply)/(\d+)',post),
url(r'^new_thread/(\d+)/$',new_thread),
url(r'^reply/(\d+)/$',reply),
url(r'^profile/(?P<pk>\w+)/$',profile),
# Examples:
# url(r'^$', 'forum.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^accounts/',include('registration.backends.default.urls')),
url(r'^admin/', include(admin.site.urls)),
)
【问题讨论】:
-
您好,欢迎来到 SO。请详细说明您在注册过程中采取的每个步骤,然后发布您遇到的确切错误。尝试从您看到的错误中找出错误在您的代码中的位置并发布该代码。
-
谢谢。我已经更新了问题。
标签: django django-templates django-admin