[Solved]-Differentiating between different post requests on the same page in Django views.py

18👍

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
👤janos

Leave a comment