30đź‘Ť
Don’t forget to add the name and value parameters to your “button” or “input type=submit” fields of the form. I’ve had the same problem once and it drove me crazy.
In short, as request.POST contains a dict, you need a key and a value. The key corresponds to the name parameter of your button, and the dict’s value to the button’s value.
<button type="submit" value="preview">Preview</button>
won’t be reflected in request.POST (there’s no key for the POST dictionary!), whereas
<button type="submit" value="preview" name="preview">Preview</button>
will have a key “preview” with value “preview”.
0đź‘Ť
For some reason, in Chrome, when I had two buttons using <input/>
tags, it would actually treat the button I didn’t click as an input. That way, when I tested something like 'sendPaperButton' in request.POST
, it would return the opposite of what I wanted.
I changed these to <button></button>
tags and it worked fine.
- Django: model has two ManyToMany relations through intermediate model
- Django/Python: generate pdf with the proper language
- Where do I register an rq-scheduler job in a Django app?
- Adding a "through" table to django field and migrating with South?
- Succinct way of updating a single field of a django model object