Home > front end >  Jdango in the template HTML file cannot be received view variables are coming
Jdango in the template HTML file cannot be received view variables are coming

Time:09-24

I early django, according to the code of a book on, in the view defines an index function, will get data from the database to the HTML file, but open 127.0.0.1: nothing shows that after 8000, add print validation is successful to read data from the database, the code is as follows, please each great god help have a look, thanks a lot!
# views. Py
Def index (request) :
Type_list=Product. Objects. Values (' type '). Distinct ()
# print (type_list)
Name_list=Product. Objects. Values (' name ', 'type')
# print (name_list)
Title='front page'
Return render (request, 'index.html, context=locals (), the status=200)

# models. Py
The class Product (models. Model) :
Id=models. IntegerField (primary_key=True)
Name=models. CharField (max_length=50)
Type=models. CharField (max_length=20)
Objects=models. The Manager ()

# urls. Py
Urlpatterns=[
Path (' 'views. The index)
]

# index. The HTML


{{title}} & lt;/title> <br/><meta charset="UTF-8"> <br/></head> <br/><body> <br/><Div> <br/><Ul id="cate_box" & gt; <br/>{% for type in type_list %} <br/><Li> <br/><H3 & gt; <A href="https://bbs.csdn.net/topics/#" & gt; {{type. The type}} & lt;/a> </h3 & gt; <br/><P> <br/>{% for the name in name_list %} <br/>{% if name. Type==type. The type %} <br/><Span> {{name. The name}} & lt;/span> <br/>Endif {% %} <br/>{% endfor %} <br/></p> <br/></li> <br/>{% endfor %} <br/></ul> <br/></div> <br/></body> <br/></html> </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/26445.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/26445.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/26444.html'>I want to access Intranet network circumstances</a></div> <div class="detail-arr-right">Next:<a href='/frontend/26446.html'>NullPointerException Fastdfs_ tracker. GetConnection ()</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=other' target='_blank'>other</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>