开发者

Django request.META 2

I understand everything from this code:

def display_meta(request):
    values = request.META.items()
    values.sort()
    html = []
    for k, v in values:
        html.append('<tr><td>%s</td><td>%s</td></tr>' % (k, v))
    return HttpResponse('<table&开发者_开发技巧gt;%s</table>' % '\n'.join(html))

Except this line: '\n'.join(html)

So \n creates a new line for every table I assume. But what does join(html) do?


It basically puts a newline between every item in html.

So if

html = ['<!DOCTYPE html>', '<html>', '<body>', '<p>']

that piece of code will create this string:

"""
<!DOCTYPE html>
<html>
<body>
<p>
"""

http://docs.python.org/library/stdtypes.html#str.join

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜