0

これが私のdjangoビューの2つの関数です。1 つ目と 2 つ目は同じことを行う必要があります。しかし、最初の関数を使用すると、最後の行に「outside function」、つまり「return HttpResponse(output)」と表示されます。

何故ですか?

ありがとう、シヤム

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)
4

1 に答える 1

1

メソッドの一部と見なすには、その行をインデントする必要があるためですmain_page

于 2012-07-27T17:06:00.850 に答える