有很多方法可以在Django中实现用户身份验证。我使用模型表单来创建表单和注册过程。现在我真的不知道登录。我不能使用内置登录,因为我的模型(它被称为)和django的内置用户模型之间没有关系。我想得到一些关于方式的建议。这是我的代码:Account
views.py:
def sign_up(request):
context = {}
form = SignUpForm(request.POST or None, request.FILES or None)
if form.is_valid():
form.save()
return redirect('/')
else:
form = SignUpForm(request.POST or None, request.FILES or None)
context['form'] = form
return render(request, "sign_up.html", context)
models.py:
class Account(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField(max_length=60)
username = models.CharField(max_length=30)
password = models.CharField(max_length=60)
university_name = models.ForeignKey(
University, on_delete=models.CASCADE, blank=True, null=True)
isPhysicalAccount = models.BooleanField(default=False)
def __str__(self):
return self.username
forms.py:
lass SignUpForm(forms.ModelForm):
class Meta:
model = Account
fields = "__all__"
def __init__(self, *args, **kwargs):
super(SignUpForm, self).__init__(*args, **kwargs)
小唯快跑啊
陪伴而非守候
相关分类