这是我的注册视图->
def signup(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
print('hello')
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
account = Account(user=user)
account.save()
login(request, user)
return redirect('/gallery/index')
else:
form = UserCreationForm()
return render(request, 'accounts/signup.html', {'form': form})
这是我的帐户模型->
class Account(models.Model):
user = models.OneToOneField(User,
related_name="profile",on_delete=models.CASCADE)
following=models.ManyToManyField(User,related_name="followers",null=True,blank=True)
这是我遇到的错误-
视图account.views.signup没有返回HttpResponse对象。 它返回None。
每当我提交表格时,我都会收到此错误。我默认情况下使用的是django管理员注册表单
答案 0 :(得分:1)
尝试
def signup(request):
form = UserCreationForm()
if request.method == 'POST':
form = UserCreationForm(request.POST)
print('hello')
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=username, password=raw_password)
account = Account(user=user)
account.save()
login(request, user)
return redirect('/gallery/index')
else:
form = UserCreationForm()
return render(request, 'accounts/signup.html', {'form': form})