Django post请求什么也不做

2024-09-30 18:16:18 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我甚至不知道如何去寻找发生同样事情的人。你知道吗

我在django网站上工作,我的表单不会发布到我的数据库中,相反,我会被重定向到包含表单中信息的URL,如下所示:

<form id="form">
      <input type="hidden" id="compinp" name="compinp">
      <input maxlength="20" onkeyup="showpost()" name="title" id="titleinput">
                    {{ captcha }}
</form>

当compinp是其他一些被发布的数据时,{captcha}}是一个reCaptcha复选框,它工作得很好,当所有内容都被填充并被发布时,我不是从views.py运行post函数,而是被重定向到以下位置:

http://localhost:8000/newentry/?compinp=XXXX&title=XXXX&g-recaptcha-response="xxxx-xxxx-xxxx"

它是通过jQuery通过表单外部的按钮发布的,不过我尝试在它内部添加一个submit按钮,得到了完全相同的结果。你知道吗

处理如下内容的views.py函数:

def newentry(request):
    if request.method == "GET" and request.user.is_authenticated():
        #creating objects for the view, works fine too
        return render(request, "newentry.html",
                      {"champlist": complist, "captcha": captcha})
    elif request.method == "POST" and request.user.is_authenticated():
        captcha = Captcha(request.POST)
        title = request.POST.get("title", False)
        compname = request.POST.get("compinp", False)
        comp = Comp.objects.get(title=compname)
        if captcha.is_valid() and title and compname:
            newe= entry_generator(request.user, title, comp)
            newe.save()
            return redirect('/')
        else:
            return redirect('/')
    else:
         handle_home(request.method, request.user)

这个视图试图在同一个项目中发布来自另一个应用程序的模型,如果这使它有所不同的话。你知道吗

我在请求检查post之后添加了一个print尝试,它没有打印任何内容。你知道吗

不知道我还能提供什么信息来帮助你,如果你需要的话,就问(:


Tags: andformid表单内容titleisrequest
1条回答
网友
1楼 · 发布于 2024-09-30 18:16:18

您需要添加表单方法post:

<form id="form" method="post">
  <input type="hidden" id="compinp" name="compinp">
  <input maxlength="20" onkeyup="showpost()" name="title" id="titleinput">
                {{ captcha }}
</form>

相关问题 更多 >