Django表单请求方法始终是GET

发布于 2025-01-15 23:13:19 字数 599 浏览 1 评论 0原文

这是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2025-01-22 23:13:19

您的表格中没有提及任何操作。视图函数需要修改以保持简单和可读。

输入图片此处描述

There is no action mentioned in your form. View function needs to be modified to keep it simple and readable.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文