Nhận máy chủ Django của riêng bạn
mẫu.html
lượt xem.py
 <!DOCTYPE html> <html> <body> {% spaceless %} <ul> {% for x in fruits %} <li>{{ x }}</li> {% endfor %} </ul> {% endspaceless %} <p>Right-click the result and view the page source. The entire HTML code is written in one line.</p> <p>Check out views.py to see what the fruits variable looks like.</p> </body> </html>
 from django.http import HttpResponse from django.template import loader def testing(request): template = loader.get_template('template.html') context = { 'fruits': ['Apple', 'Banana', 'Cherry', 'Orange'] } return HttpResponse(template.render(context, request))
127.0.0.1:8000/thử nghiệm