I'm looking for create some
SQL queries
views.py
def Test(request) :
cursor = connection.cursor()
cursor.execute('''SELECT * FROM BirthCertificate_people WHERE `name` = "Dupont" AND `city` = "New-York"''')
row = cursor.fetchone()
print row
template = loader.get_template('test.html')
return HttpResponse(template.render(request))
test.html
<h2 align="center"> SQL Queries display </align> </h2>
{% block content %}
<!-- What I write there --> {{ }}
{% endblock %}
You need to pass the row as a context so that it can be accessed in the html. One way to do this is by 1) Inside your views.py import render
from django.shortcuts import render
2) Now pass the template and context together
def Test(request) :
cursor = connection.cursor()
cursor.execute('''SELECT * FROM BirthCertificate_people WHERE `name` = "Dupont" AND `city` = "New-York"''')
row = cursor.fetchone()
print row
context = {"row":row}
return render(request, "test.html", context)
3) Now inside your template "test.html" you can access your row:-
<h2 align="center"> SQL Queries display </align> </h2>
{% block content %}
{{ row }}
{% endblock %}