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