I have a web page that I am looking to be able to modify dynamically with multiple post requests. basically there are two methods that the user can submit text to be uploaded into models; one is through a text input field and the other is through a file upload field. How do I set up my python conditionals to do this? I want to be able to differentiate between the two post request with if and statements. What is the differentiating variable that I should use to tell these two apart. My views.py so far has the text input working.
def homesite(request):
corpusitems = CorpusItem.objects.order_by('name')
if (request.method == 'POST'):
f = CorpusItemForm(request.POST)
if f.is_valid():
new_corpusitem = f.save()
return render(request, 'content.html', {'corpusitems': corpusitems})
Submit buttons in HTML have name and value properties. For example if you have:
<form>
<input type="submit" name="action" value="Send"/>
<input type="submit" name="action" value="Hello"/>
</form>
Then in Django you can distinguish the two submit actions by the value of action
:
if request.POST['action'] == 'Send':
# do this
elif request.POST['action'] == 'Hello':
# do that
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With