Django 请求.META
如果我想显示 request.META 字典的多个项目:
如何将例如两个放入此字符串格式:
def myurl(request):
return HttpResponse("You are %s" % request.META['USER'], "Your IP Adress is " % request.META['REMOTE_ADDR'])
不起作用。
另外,我如何显示/提取该词典的选择性项目的任何想法。
如果我想通过模板运行多个。我如何将其插入 html 模板中:
例如
{{request.META }} 。这对所有人都有效吗?如何在每一行中显示它们?
如果我想要例如:
HTTP_COOKIE
QUERY_STRING
HTTP_CONNECTION
显示该 3 的最佳方式是什么?
谢谢!
If I want to display more than one item of the request.META dictionary:
How can I put e.g. two in this string format:
def myurl(request):
return HttpResponse("You are %s" % request.META['USER'], "Your IP Adress is " % request.META['REMOTE_ADDR'])
does not work.
Also, any ideas how I can display/extract selective items of that dictionary.
If I want to run more than one via a template. How would I insert that in the html template:
e.g.
{{request.META }} . Does that works for all? How can I display them one in each line?
if I want e.g. just:
HTTP_COOKIE
QUERY_STRING
HTTP_CONNECTION
What would be the best way to display that 3 ?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新(阅读OP对此答案的评论后)
这里的
模板
只是一个带有嵌入格式选项的字符串。1) 它不必被称为
template
2) 您可以完全取消它,使其内联。这纯粹是编码风格/偏好的问题。
原始答案
对问题第一部分的快速而肮脏的回答:
Update (after reading OP's comment to this answer)
The
template
here is just a string with embedded format options.1) It doesn't have to be called
template
2) You can do away with it altogether make it inline. This is purely a matter of coding style/preference.
Original Answer
Quick and dirty answer to the first part of your question:
使用 RequestContext:
然后您将可以访问 request.META 及其包含的所有内容。您可以使用调试模板标签来打印您的上下文。
Use RequestContext:
You will then have access to request.META and everything it contains. You may use the debug template tag to print your context.