request.META 是一个Python字典,包含了所有本次HTTP请求的Header信息,比如用户IP地址和用户Agent。通过request.META.items()可得到这个字典。要求将META信息输出到网页。
输出结果
<html> <head><title>{{index_title}}</title></head> <body> {% block mainbody %} {%for key,value in index_text %} <p><tr><td>{{key}}</td><td>{{value}}</td></tr></p> {%endfor%} {% endblock %} </body> </html>views.py
from django.shortcuts import render # Create your views here. def display_meta(request): values = request.META.items() html = {} html['index_title']='Display META' html['index_text']=values return render(request,"index.html",html)
<html> <head><title>{{index_title}}</title></head> <body> {% block mainbody %} {{index_text}} {% endblock %} </body> </html>views.py
from django.shortcuts import render # Create your views here. def display_meta(request): values = request.META.items() html = {} html['index_text']=" " html['index_title']='Display META' for k, v in values: html['index_text']+=('<tr><td>%s</td><td>%s</td></tr>' % (k, v)) return render(request,"index.html",html)输出结果
原文地址:http://blog.csdn.net/a359680405/article/details/43051785