Django - How to do an if statement if button is clicked

自闭症网瘾萝莉.ら 提交于 2020-01-05 14:03:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!