[[email protected] muahao02]# vim 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"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> muahao02</title> </head> <body> <h1>hello muahao02</h1> </body> </html>
[[email protected] muahao02]# vim blog/views.py
from django.template import loader,Context,Template from django.http import HttpResponse def index(req): t = loader.get_template(‘index.html‘) c = Context({‘uname‘:‘Alen‘}) html = t.render(c) return HttpResponse(html) def index1(req): t = Template(‘<h1>hello {{uname}}</h1>‘) c = Context({‘uname‘:‘Jack‘}) return HttpResponse(t.render(c))
[[email protected] muahao02]# vim muahao02/urls.py
from django.template import loader,Context,Template from django.http import HttpResponse def index(req): t = loader.get_template(‘index.html‘) c = Context({‘uname‘:‘Alen‘}) html = t.render(c) return HttpResponse(html) def index1(req): t = Template(‘<h1>hello {{uname}}</h1>‘) c = Context({‘uname‘:‘Jack‘}) return HttpResponse(t.render(c))
时间: 2024-10-12 03:55:54