Django FormView,无需重定向即可返回 [英] Django FormView, Return without redirecting
问题描述
我想知道是否有可能停留在同一页面上而无需使用FormView将其重新加载到success_url.理想情况下,我只希望发送通知或什么都不做.只需处理表格.如果有道理.
I would like to know if it is possible to stay on the same page without having it reload to a success_url using FormView. Ideally I would it to just send a notification or do nothing at all. just process the form. if this makes sense.
我的代码当前在views.py
my code currently looks like this in views.py
class Capture(FormView):
template_name = "capture.html"
success_url = '/'
form_class = TestForm
def form_valid(self, form, *args, **kwargs):
print("Submit Capture")
form.save_screenshot()
return super().form_valid(form)
如何更改此设置以不重新加载我的页面.欢迎使用其他库或方法,而不仅限于使用FormView.
how can I change this to not reload my page. Other libraries or methods are welcomed and not limited to using FormView.
推荐答案
在POST成功后,您应始终进行重定向,以避免两次提交的任何问题(例如,如果用户按下Refresh).但是没有什么能阻止您重定向回同一页面.
You should always redirect after a successful POST, to avoid any issues with double submissions (if the user presses Refresh, for example). But there's nothing to stop you redirecting back to the same page.
这篇关于Django FormView,无需重定向即可返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!