That what you showing is a template. Template receive a data from a view function.
So that function located in a views.py returning that template, with interpolated data (rendered final html). So in may be in context or in other variable.
Solution 1 :
Problem :
It is necessary to obtain information from the selected cell from the html file and then work with it in views.py. Is it possible and how to do it? Thank you in advance!
<tbody>
{% for element in qz %}
<tr>
<td class="counterCell"></td>
<td style="display: none">{{ element.0 }}</td> <!-- information is needed for this cell when it is selected -->
<td>{{ element.1 }}</td>
<td>{{ element.2 }}</td>
<td><span class="glyphicon glyphicon-trash"></span></td>
</tr>
{% endfor %}
</tbody>
views.py:
cursor = connection.cursor()
cursor1 = connection.cursor()
cursor2 = connection.cursor()
cursor.execute(
"SELECT sites.site_title, sites.url FROM sites, my_sites, auth_user WHERE auth_user.id = my_sites.id_user AND sites.id = my_sites.id_site AND auth_user.id =" + str(
request.user.id))
cursor1.execute(
"SELECT sites.site_title, sites.url FROM sites, my_sites, auth_user WHERE auth_user.id = my_sites.id_user AND sites.id = my_sites.id_site AND auth_user.id =" + str(
request.user.id))
cursor2.execute(
"SELECT sites.id, sites.site_title, sites.url FROM sites, my_sites, auth_user WHERE auth_user.id = my_sites.id_user AND sites.id = my_sites.id_site AND auth_user.id =" + str(
request.user.id))
q = [str(row[0]) for row in cursor.fetchall()]
z = [str(row[1]) for row in cursor1.fetchall()]
x = [str(row[0]) for row in cursor2.fetchall()]
qz = [(x[i], q[i], z[i]) for i in range(len(q))]
return render(request, 'main/my_newsagent.html', {'qz': qz})
Comments
Comment posted by Dmitry Yudin
post a views.py file here
Comment posted by The offcial tutorial is here
Do yourself (and whoever will have to maintain this code) a favor and learn to properly use Django models (and forms etc).
Comment posted by bruno desthuilliers
PS: given your question, you certainly want to learn about html forms and the HTTP protocol too.