问题
I want the user to click a button on my website, and when it is clicked I want i = i + 1. So far I have this code that doesn't work
# On html file
<form method='get' action='#'>
<input type="submit" value="Next" name="Next"/>
</form>
# In django views
if request.GET.get('Name'):
print('user clicked summary')
回答1:
Try -
# On html file
<form method='get' action='#'>
<input type="submit" value="Next" name="Next"/>
</form>
# In django views
if request.GET.get('Next') == 'Next':
print('user clicked summary')
Because the name of the button is 'Next'
not 'Name'
来源:https://stackoverflow.com/questions/31911264/django-how-to-do-an-if-statement-if-button-is-clicked