好的,所以我的注册工作正常。我在某个地方出现了一个错误,即错过了以下
的错误ts.dat.pcict
[1] "2006-01-01" "2006-01-02" "2006-01-03" "2006-01-04" "2006-01-05"
[6] "2006-01-06" "2006-01-07" "2006-01-08" "2006-01-09" "2006-01-10"
[11] "2006-01-11" "2006-01-12" "2006-01-13" "2006-01-14" "2006-01-15"
[16] "2006-01-16" "2006-01-17" "2006-01-18" "2006-01-19" "2006-01-20"
[21] "2006-01-21" "2006-01-22" "2006-01-23" "2006-01-24" "2006-01-25"
[26] "2006-01-26" "2006-01-27" "2006-01-28" "2006-01-29" "2006-01-30"
[31] "2006-02-01" "2006-02-02" "2006-02-03" "2006-02-04" "2006-02-05"
[36] "2006-02-06" "2006-02-07" "2006-02-08" "2006-02-09" "2006-02-10"
[41] "2006-02-11" "2006-02-12" "2006-02-13" "2006-02-14" "2006-02-15"
[46] "2006-02-16" "2006-02-17" "2006-02-18" "2006-02-19" "2006-02-20"
[51] "2006-02-21" "2006-02-22" "2006-02-23" "2006-02-24" "2006-02-25"
[56] "2006-02-26" "2006-02-27" "2006-02-28" "2006-02-29" "2006-02-30"
[61] "2006-03-01" "2006-03-02" "2006-03-03" "2006-03-04" "2006-03-05"
[66] "2006-03-06" "2006-03-07" "2006-03-08" "2006-03-09" "2006-03-10"
[71] "2006-03-11" "2006-03-12" "2006-03-13" "2006-03-14" "2006-03-15"
[76] "2006-03-16" "2006-03-17" "2006-03-18" "2006-03-19" "2006-03-20"
[81] "2006-03-21" "2006-03-22" "2006-03-23" "2006-03-24" "2006-03-25"
[86] "2006-03-26" "2006-03-27" "2006-03-28" "2006-03-29" "2006-03-30"
[91] "2006-04-01" "2006-04-02" "2006-04-03" "2006-04-04" "2006-04-05"
[96] "2006-04-06" "2006-04-07" "2006-04-08" "2006-04-09" "2006-04-10"
[101] "2006-04-11" "2006-04-12" "2006-04-13" "2006-04-14" "2006-04-15"
[106] "2006-04-16" "2006-04-17" "2006-04-18" "2006-04-19" "2006-04-20"
[111] "2006-04-21" "2006-04-22" "2006-04-23" "2006-04-24" "2006-04-25"
[116] "2006-04-26" "2006-04-27" "2006-04-28" "2006-04-29" "2006-04-30"
[121] "2006-05-01" "2006-05-02" "2006-05-03" "2006-05-04" "2006-05-05"
[126] "2006-05-06" "2006-05-07" "2006-05-08" "2006-05-09" "2006-05-10"
[131] "2006-05-11" "2006-05-12" "2006-05-13" "2006-05-14" "2006-05-15"
[136] "2006-05-16" "2006-05-17" "2006-05-18" "2006-05-19" "2006-05-20"
[141] "2006-05-21" "2006-05-22" "2006-05-23" "2006-05-24" "2006-05-25"
[146] "2006-05-26" "2006-05-27" "2006-05-28" "2006-05-29" "2006-05-30"
[151] "2006-06-01" "2006-06-02" "2006-06-03" "2006-06-04" "2006-06-05"
[156] "2006-06-06" "2006-06-07" "2006-06-08" "2006-06-09" "2006-06-10"
[161] "2006-06-11" "2006-06-12" "2006-06-13" "2006-06-14" "2006-06-15"
[166] "2006-06-16" "2006-06-17" "2006-06-18" "2006-06-19" "2006-06-20"
[171] "2006-06-21" "2006-06-22" "2006-06-23" "2006-06-24" "2006-06-25"
[176] "2006-06-26" "2006-06-27" "2006-06-28" "2006-06-29" "2006-06-30"
[181] "2006-07-01" "2006-07-02" "2006-07-03" "2006-07-04" "2006-07-05"
[186] "2006-07-06" "2006-07-07" "2006-07-08" "2006-07-09" "2006-07-10"
[191] "2006-07-11" "2006-07-12" "2006-07-13" "2006-07-14" "2006-07-15"
[196] "2006-07-16" "2006-07-17" "2006-07-18" "2006-07-19" "2006-07-20"
[201] "2006-07-21" "2006-07-22" "2006-07-23" "2006-07-24" "2006-07-25"
[206] "2006-07-26" "2006-07-27" "2006-07-28" "2006-07-29" "2006-07-30"
[211] "2006-08-01" "2006-08-02" "2006-08-03" "2006-08-04" "2006-08-05"
[216] "2006-08-06" "2006-08-07" "2006-08-08" "2006-08-09" "2006-08-10"
[221] "2006-08-11" "2006-08-12" "2006-08-13" "2006-08-14" "2006-08-15"
[226] "2006-08-16" "2006-08-17" "2006-08-18" "2006-08-19" "2006-08-20"
[231] "2006-08-21" "2006-08-22" "2006-08-23" "2006-08-24" "2006-08-25"
[236] "2006-08-26" "2006-08-27" "2006-08-28" "2006-08-29" "2006-08-30"
[241] "2006-09-01" "2006-09-02" "2006-09-03" "2006-09-04" "2006-09-05"
[246] "2006-09-06" "2006-09-07" "2006-09-08" "2006-09-09" "2006-09-10"
[251] "2006-09-11" "2006-09-12" "2006-09-13" "2006-09-14" "2006-09-15"
[256] "2006-09-16" "2006-09-17" "2006-09-18" "2006-09-19" "2006-09-20"
[261] "2006-09-21" "2006-09-22" "2006-09-23" "2006-09-24" "2006-09-25"
[266] "2006-09-26" "2006-09-27" "2006-09-28" "2006-09-29" "2006-09-30"
[271] "2006-10-01" "2006-10-02" "2006-10-03" "2006-10-04" "2006-10-05"
[276] "2006-10-06" "2006-10-07" "2006-10-08" "2006-10-09" "2006-10-10"
[281] "2006-10-11" "2006-10-12" "2006-10-13" "2006-10-14" "2006-10-15"
[286] "2006-10-16" "2006-10-17" "2006-10-18" "2006-10-19" "2006-10-20"
[291] "2006-10-21" "2006-10-22" "2006-10-23" "2006-10-24" "2006-10-25"
[296] "2006-10-26" "2006-10-27" "2006-10-28" "2006-10-29" "2006-10-30"
[301] "2006-11-01" "2006-11-02" "2006-11-03" "2006-11-04" "2006-11-05"
[306] "2006-11-06" "2006-11-07" "2006-11-08" "2006-11-09" "2006-11-10"
[311] "2006-11-11" "2006-11-12" "2006-11-13" "2006-11-14" "2006-11-15"
[316] "2006-11-16" "2006-11-17" "2006-11-18" "2006-11-19" "2006-11-20"
[321] "2006-11-21" "2006-11-22" "2006-11-23" "2006-11-24" "2006-11-25"
[326] "2006-11-26" "2006-11-27" "2006-11-28" "2006-11-29" "2006-11-30"
[331] "2006-12-01" "2006-12-02" "2006-12-03" "2006-12-04" "2006-12-05"
[336] "2006-12-06" "2006-12-07" "2006-12-08" "2006-12-09" "2006-12-10"
[341] "2006-12-11" "2006-12-12" "2006-12-13" "2006-12-14" "2006-12-15"
[346] "2006-12-16" "2006-12-17" "2006-12-18" "2006-12-19" "2006-12-20"
[351] "2006-12-21" "2006-12-22" "2006-12-23" "2006-12-24" "2006-12-25"
[356] "2006-12-26" "2006-12-27" "2006-12-28" "2006-12-29" "2006-12-30"
[361] "2007-01-01" "2007-01-02" "2007-01-03" "2007-01-04" "2007-01-05"
[366] "2007-01-06" "2007-01-07" "2007-01-08" "2007-01-09" "2007-01-10"
[371] "2007-01-11" "2007-01-12" "2007-01-13" "2007-01-14" "2007-01-15"
[376] "2007-01-16" "2007-01-17" "2007-01-18" "2007-01-19" "2007-01-20"
[381] "2007-01-21" "2007-01-22" "2007-01-23" "2007-01-24" "2007-01-25"
[386] "2007-01-26" "2007-01-27" "2007-01-28" "2007-01-29" "2007-01-30"
当我取出登录部分时,表格的其余部分有效,所以我倾向于倾斜。我已经包含了models.py urls.py和两个html的部分内容我希望有人可以看到错误我失踪了
索引HTML
Request Method: POST
Request URL: http://localhost:8000/users/%7Burl%20'users:login'%20%25%7D
Using the URLconf defined in loginReg.urls, Django tried these URL patterns, in this order:
^users/ ^$ [name='index']
^users/ ^register$ [name='register']
^users/ ^success$ [name='success']
^users/ ^login$ [name='login']
^users/ ^logout$ [name='logout']
The current URL, users/{url 'users:login' %}, didn't match any of these.
Models.py
<!DOCTYPE html>
<html>
<head>
<title>Login and Registration</title>
</head>
<body>
{% if messages %}
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}
{% endif %}
<div class="register">
<h1>Register</h1>
<form class="" action="{% url 'users:register' %}" method="post">
{% csrf_token %}
<p>First Name: <input type="text" name="first_name" value=""></p>
<p>Last Name: <input type="text" name="last_name" value=""></p>
<p>Email: <input type="text" name="email" value=""></p>
<p>Password: <input type="Password" name="password" value=""></p>
<p>Confirm Password: <input type="password" name="confirm_password" value=""></p>
<input type="submit" name="" value="Register">
</form>
</div>
<div class="login">
<h1>Login</h1>
{% csrf_token %}
<form class="" action="{url 'users:login' %}" method="post">
<p>Email: <input type="text" name="email" value=""></p>
<p>Password: <input type="Password" name="password" value=""></p>
<input type="submit" name="" value="Login">
</form>
</div>
</body>
</html>
Urls.py
来自django.conf.urls导入网址,包含 来自。导入视图
from __future__ import unicode_literals
from django.db import models
import re, bcrypt
EMAIL_REGEX = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$')
class UserManager(models.Manager):
def add_user(self, postData):
errors = []
if not len(postData['first_name']):
errors.append('First name is required')
if len(postData['last_name']) < 2:
errors.append('Last name must be at least 2 characters long!')
if not len(postData['email']):
errors.append('Email is required!')
if not EMAIL_REGEX.match(postData['email']):
errors.append('Please enter a valid email!')
check_email = self.filter(email = postData['email'])
if check_email:
errors.append('Sorry email already exist!')
if len(postData['password']) < 8:
errors.append('Password must be at least 8 characters!')
if not postData['password'] == postData['confirm_password']:
errors.append('Passwors must match!')
modelsResponse = {}
if errors:
# failed validations
modelsResponse ['isRegistered'] = False
modelsResponse['errors'] = errors
else:
# passed validations, create a new user
hashed_password = bcrypt.hashpw(postData['password'].encode(), bcrypt.gensalt())
user = self.create(first_name = postData['first_name'] , last_name = postData['last_name'], password = hashed_password)
modelsResponse ['isRegistered']= True
modelsResponse['user'] = user
return modelsResponse
def login_user(self, postData):
user = self.filter(email = postData['email'])
errors = []
modelsResponse = {}
if not user:
#invalid email
errors.append('Invalid email!')
else:
#found a user match, check the password to see if they match
if bcrypt.checkpw(postData['password'].encode(), user[0].password.encode()):
#login the user
modelsResponse['isLoggedIn'] = True
modelsResponse['user'] = user[0]
else:
# invalid email password combination
errors.append('Invalid email/password combination!')
if errors:
modelsResponse['isLoggedIn'] = False
modelsResponse['errors'] = errors
return modelsResponse
class User(models.Model):
first_name = models.CharField(max_length = 50)
last_name = models.CharField(max_length = 50)
email = models.CharField(max_length = 100)
password = models.CharField(max_length =100)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
objects = UserManager()
views.py
urlpatterns = [
url(r'^$', views.index, name= 'index'),
url(r'^register$', views.register, name = 'register' ),
url(r'^success$', views.success, name = 'success'),
url(r'^login$', views.login, name = 'login' ),
url(r'^logout$', views.logout, name = 'logout'),
]
答案 0 :(得分:1)
你有一个错字
{url 'users:login' %}
应该是
{% url 'users:login' %}
#^ missing %