python - 我在 python 中的 POST 方法有问题
问题描述
我正在使用 windows(10) 和 django 库我想在我的电子商务中创建注册选项,所以我制作了一个名为 accounts 的应用程序,我在它的视图中写道
from django.shortcuts import render
from django.contrib.auth.forms import UserCreationForm
def signup(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
print('In Post')
if form.is_valid:
form.save()
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
print(username , password)
else:
form = UserCreationForm()
context = {'form' : form}
return render(request , 'registration/signup.html' , context)
我在我的 signup.html 页面中写道
{% extends "base.html" %}
{% block body %}
<main class="mt-5">
<div class="container mynav">
<form action="" method="post">
{% csrf_token %}
{{form}}
<button type="submit" class="btn btn-primary">Sign up</button>
</form>
</div>
</main>
{% endblock body %}
当我尝试运行 POST 方法时出现问题,他说
The view accounts.views.signup didn't return an HttpResponse object. It returned None instead.
在 CMD(=terminal)The User could not be created because the data didn't validate.
中我写什么来解决这个问题?谢谢。
解决方案
推荐阅读
- android - RxJava“java.lang.AssertionError:位置 0 的值不同;预期”的 Roboelectric 测试用例失败
- angular - 角材料表不渲染数据
- excel - Excel VBA - 为整个单元格范围运行的宏
- json - 如何将mongodb数据解码为结构
- karate - 空手道检查 xml 请求是否包含特定值
- rasa-nlu - 如何在 RASA 聊天机器人中添加按钮?
- github - github项目和存储库中的项目有什么区别?
- android - 构建器在 aftertextchanged 中未更改,用于片段中的编辑文本
- angular - ngx datepicker:设置前几年的初始年份值
- javascript - 如何在 Bootstrap pincode-input.js 中显示 PIN/密码