我正在使用电子邮件验证创建注册页面,但是我遇到类型错误mailvalidation()收到了意外的关键字参数'user_id'
views.py
def signup(request):
if request.method=='POST':
username=request.POST['username']
email=request.POST['email']
password=request.POST['password']
cpassword=request.POST['cpassword']
userdetails(name=username,email=email,password=password).save()
user = userdetails.objects.get(email=email)
token = default_token_generator.make_token(user)
#print(user.id)
#print(user.email)
#print(user.name)
#print(token)
mailvalidation(user_id=user.id, user_email=user.email, user_name=user.name, key=token).save()
sendmail(email, token)
return HttpResponse('We have sent a email verification please check your email')
return render(request,'credentials/register.html')
models.py
class userdetails(models.Model):
name=models.CharField(max_length=50)
email=models.CharField(max_length=50)
password=models.CharField(max_length=20)
valid_email=models.IntegerField(default=0)
last_login=models.DateTimeField(default=today)
class Meta:
db_table='user_details'
class mailvalidation(models.Model):
user_id=models.IntegerField(default=0)
user_email=models.EmailField(max_length=100)
user_name=models.CharField(max_length=100)
key=models.TextField()
class Meta:
db_table='mail_validation'
答案 0 :(得分:1)
user_id
应该ForeignKey
因此,您可以更改此
user_id = models.IntegerField(default=0)
到
user = models.ForeignKey(userdetails, on_delete=models.CASCADE)
此处user
字段将重复为user_id
,因此无需向用户添加_id
。