Django表单请求方法始终是GET
这是html代码:
<form method='POST'>{% csrf_token %}
{{ form.as_p }}
<input type='submit' value='save'/>
</form>
这是url.py中的路径:
path('student/create/', student_create_view, name='student-create')
这是我在views.py中的代码:
def student_create_view(request):
form = StudentForm(request.POST or None)
if form.is_valid():
form.save()
form = StudentForm
context = {
'form': form
}
return render(request, "personnel/student_create.html", context)
我还尝试使用action属性并在路径末尾添加或删除“/”。
This is the html code:
<form method='POST'>{% csrf_token %}
{{ form.as_p }}
<input type='submit' value='save'/>
</form>
This is the path in url.py:
path('student/create/', student_create_view, name='student-create')
This is my code in views.py:
def student_create_view(request):
form = StudentForm(request.POST or None)
if form.is_valid():
form.save()
form = StudentForm
context = {
'form': form
}
return render(request, "personnel/student_create.html", context)
I also tried using action attribute and adding or removing "/" to the end of the path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的表格中没有提及任何操作。视图函数需要修改以保持简单和可读。
There is no action mentioned in your form. View function needs to be modified to keep it simple and readable.