Normal parameter passing
Modify Blog/templates/index.html
<?xml version="1.0"encoding="UTF-8"?> <! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 strict//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-STRICT.DTD">"http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">"Content-type"Content="text/html; Charset=utf-8"/> <title>{{title}}</title>Modify blog/views.py
from Import Render_to_response def Index (req): return render_to_response ('index.html', {'title' :'my page'user':'alu02 '})
Test interface
Dictionary parameter passingModify blog/views.py
fromDjango.shortcutsImportRender_to_responsedefIndex (req): User= {'name':'alu02',' Age': 1,'Sex':'male'} returnRender_to_response ('index.html',{'title':'my page','User': User})
Modify Blog/templates/index.html
<?xml version="1.0"encoding="UTF-8"?> <! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 strict//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-STRICT.DTD">"http://www.w3.org/1999/xhtml"xml:lang="en"lang="en">"Content-type"Content="text/html; Charset=utf-8"/> <title>{{title}}</title>Interface Testing
Similarly, we can pass an instance of a class to use properties and methods
Calling variables in HTML templates