How to handle a button click in Django project? -
i have form below:
<form action="{% url clicked %}" method="get"> <input type="submit" value="button" name="btn"/> </form>
url
:
url(r'^clicked/$', views.button_clicked, name='clicked'),
whenever click on button, should redirect page , return json file.
def button_clicked(request): if request.get.get('btn'): return httpresponseredirect('/clicked/') to_json = { "key1": "value1", "key2": "value2" } return httpresponse(simplejson.dumps(to_json), mimetype='application/json')
i'm wondering if best approach deal problem above.
Comments
Post a Comment