[英]Invalid syntax error in view.py in django
I can't figure out what i've done wrong here.我无法弄清楚我在这里做错了什么。 In my views.py.
在我的 views.py 中。
def register(request):
if request.method == 'POST'
form = UserCreationForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
return redirect('home')
else:
form = UserCreationForm()
return render(request, 'users/register.html', {'form': form})
You are missing a colon on the following line您在以下行中缺少冒号
if request.method == 'POST'
It should look like this它应该是这样的
if request.method == 'POST':
def register(request):
if request.method == 'POST': #The colon is missing here
form = UserCreationForm(request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
messages.success(request, f'Account created for {username}!')
return redirect('home')
else:
form = UserCreationForm()
return render(request, 'users/register.html', {'form': form})
您当前的第二行最后需要一个:
语句,所以它应该是:
if request.method == 'POST':
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.