2012-07-27 51 views
0

以下是您在我的django視圖中的2個功能。 第一個和第二個應該做同樣的事情。但是當我使用第一個函數時,它在最後一行說「外部函數」,即「return HttpResponse(output)」。Django查看功能似乎不起作用

這是爲什麼?

感謝, 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) 
+2

您需要縮進(標籤)多一級第一個返回 – 2012-07-27 16:58:45

回答

1

這是因爲你需要縮進該行以便它被認爲是main_page方法的一部分。

+0

謝謝ryuusenshi塞薩爾。我不知道我是如何錯過它的。 塞薩爾, 我不知道我怎麼可以標記爲有用的答案,因爲它是一個評論。如果你知道一種方式,我很樂意爲你做記號 – Rainmaker 2012-07-27 17:26:44

+0

別擔心,沒關係。我很高興它幫助 – 2012-07-27 17:31:16

+0

再次感謝,巴迪 – Rainmaker 2012-07-27 17:38:59