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
精彩评论