Here are you 2 functions in my django views.
The first one and the second should do the same thing. But when I used the first function, it says “outside function” on the last line, which is “return HttpResponse(output)”.
Why is that?
Thanks,
Shiyam
def main_page(request):
output = '''
<html>
<head><title>%s</title></head>
<body>
<h1>%s</h1><p>%s</p>
</body>
</html>
''' % (
'Django Learning',
'Welcome',
'WYou can share book marks here!'
)
return HttpResponse(output)
def main_page(request):
title_sowl = "Django Learning"
header_sowl = "Welcome"
text_sowl = "You can share book marks here"
output = u"<html><head><title>%s</title></head><body><h1>%s</h1><p>%s</p></body></html>" % (title_sowl,header_sowl,text_sowl)
return HttpResponse(output)
It’s because you need to indent that line in order for it to be considered a part of the
main_pagemethod.