I'm newbie to django.I want to print static array output in django web page.But when I'm executing the code It shows blank in my web page. So, help me to print my view.py results in web page
from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return HttpResponse("<h>Welcome</h>")
def Compare(request):
x=[98,8998,9,67,23]
y=[67,37,9,330,123,67,56,123]
x1=[2103,23,203,12,23,12]
y1=[213,23,23,12,22,12,21,21]
for i in x:
if i in y:
c=[ii for ii,val in enumerate(y) if val==i] #print c
occurance1 = i,"Occur(s)",len(c),"times" #Total number of matches
for j in c:
if x1[j]==y1[j]:
match2=i,"Secondary level match"
else:
match1= i,"Primary level match"
#return match1
else:
unoccured= i,"not in list" ##No matches
#return unoccured
return render(request,'web/base.html')
This my html
<html>
{% load staticfiles %}
<title>My site </title>
{% block content %}
<body>
{% for occurance in occurance1 %}
<h> {{ occurance }}</h>
{% endfor %}
<ul>
{% for a in unaccured %}
<p>{{a}}</p>
{% endfor %}
</ul>
</body>
{% endblock %} </html>
first you have to initialise the variables like this :
y1=[213,23,23,12,22,12,21,21]
occurance1 = []
unaccured = []
for i in x:
.....
You can do like this to pass :
context = {'occurance1': occurance1,'unaccured': unaccured}
return render(request,'web/base.html', context)
and in your html it will be good if you do like this :
{% if occurance1 %}
{% for occurance in occurance1 %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.