vendredi 18 août 2017

Django post request doing nothing

So i'm not even sure how to search for someone who had the same thing happen to them.

I'm working on a django website and my form won't post to my database, instead, i get redirected to a URL containing the information that was in the forms, like this:

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

Where compinp is some other data that gets posted, is a reCaptcha checkbox that works just fine, and when everything is filled in and getting posted, instead of running the post function from views.py, instead i get redirected to this:

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

It gets posted via jQuery through a button outside of the form, though i tried to add a submit button inside it and got the exact same thing.

The views.py function that handles that looks like this:

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)

This view tries to post models from another app in the same project, if that makes it any different.

I had added a print attempt at the right after the request check for post it didn't print anything.

Not sure what other info i can give to help, if you want any, just ask (:




Aucun commentaire:

Enregistrer un commentaire