def register(request):
flag = True
possible = 0123456789abcdefghijklmnopqrstuvwxyz
token =
length = 10
i = 0
current_datetime = datetime.datetime.now()
user = UsersModelForm()
if request.method == POST :
userf = UsersModelForm(request.POST)
username = userf.data[ username ]
password = userf.data[ password ]
passwordrepeat = userf.data[ passwordrepeat ]
email = userf.data[ email ]
if password != passwordrepeat:
flag = False
passVariable = { user :user, flag : False}
return render_to_response( register.html , passVariable, context_instance=RequestContext(request))
elif password == passwordrepeat:
while i<10:
temp = random.choice(possible)
token = token + temp
i=i+1
userf.email_token = token
userf.email_token_expiry = current_datetime + timedelta(1)
userf.save()
return HttpResponseRedirect( / )
else:
return render_to_response( register.html , {"user": user, flag : True}, context_instance=RequestContext(request))
摘自MySQL:
<代码>从博客_users中选取; 我在<代码>email_token field中拿空的数值为何?
<>strong>models.py:
class Users(models.Model):
username = models.CharField(max_length=255)
slug = models.CharField(max_length=255, default= 0 )
password = models.CharField(max_length=300)
passwordrepeat = models.CharField( Repeat Password , max_length=300)
password_token = models.CharField(max_length=300, default= 0 )
email = models.CharField(max_length=255)
email_verified = models.BooleanField(default=False)
email_token = models.CharField(max_length=255)
email_token_expiry = models.DateTimeField(auto_now_add=True)
tos = models.BooleanField(default=False)
active = models.BooleanField(default=False)
last_login = models.DateTimeField(auto_now_add=True)
last_action = models.DateTimeField(auto_now_add=True)
is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, default= 0 )
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now_add=True)
def __unicode__(self):
return self.username
class UsersModelForm(forms.ModelForm):
class Meta:
model = Users
fields = ( username , password , passwordrepeat , email )
widgets = {
password : PasswordInput(),
passwordrepeat : PasswordInput(),
}