I have the following code in my HTML file that is to created the dynamic button.
{% for i in loop_times %}
<button type="submit" class="'btn btn-lg" name="{{ i }}" id="{{ i }}" onclick="alert(this.id)" formmethod="post"><a href="{% url 'button' %}">{{i|safe}}</a></button><br><br>
{% endfor %}
This button has the url link which link to urls.py:
url(r'^button',views.data, name='button'),
The id of this buttons will dynamically created based on hw many product I have and now I want get the id of the particular buttons to pass to the python file in order for me to used the id to do analysis, so I have the following code in my view.py file
labelid = request.GET[("id", False)]
Anyone have idea on how to pass id of the dynamically buttons to my view.py, because above code not able to run, I'm very new to python and don't have any basic for my programing background hope that I can get some idea here, thanks
Try using this:
labelid = request.GET.get("id", False)
instead of this:
labelid = request.GET[("id", False)]
Your current method is trying to get ("id", False) as a dictionary value, but obviously that's not what you are trying to do.
The way I suggested will look for value id. If it cannot find it, then labelid will be set to False.