2015-05-05 139 views
-2

我想弄清楚爲什麼當我嘗試加載此頁面時,我所得到的只是一個白色屏幕。我不確定是否正確編寫了我的應用程序。有人可以向我解釋我做錯了什麼,所以我可以修復它,讓它至少在我的瀏覽器中顯示一些內容。不顯示頁面

class Page(object): 
    def __init__(self): 

     self.header = """ 
<!DOCTYPE HTML> 
<html> 
    <head> 
     <title>New York Yankees Starting Lineup/title> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 
    </head> 
    <body> 
     """ 

     self.content = "" 

     self.footer = """ 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> 
    </body> 
</html> 
    """ 

    def print_out(self): 
     template = self.header + self.content + self.footer 
     template = template.format(**locals()) 
     return template 

class ContentPage(Page): 
    def __init__(self): 
     self.player_data = '' 
     Page.__init__(self) 
     self.player_data = ''' 
     <div> 
     Name: + player_data.player_name 
     Position: + player_data.position 
     Bats: + player_data.bats 
     Throws: + player_data.throws 
     Batting Average: + player_data.avg 
     Home Runs: + player_data.hr 
     </div>''' 

    def print_out(self): 
     return self.header + self.content + self.player_data + self.footer 

更新:我仍然在努力解決這個問題。有沒有人能幫我弄清楚發生了什麼事以及如何解決它?任何幫助將受到歡迎。

回答

1

self.content被初始化爲一個空字符串,並且永遠不會改變; self.player_data可能是你希望看到的,但是這並不在任何地方使用(儘管它的名字出現在分配給self.player_data的字符串中)。

一種解決方案是將self.content而不是self.player_data分配給__init__中的ContentPage; self.player_data看起來應該是關於的播放器的信息,而不是顯示該數據的模板。

+0

我該如何告訴內容顯示player_data呢? – user3732216

+0

我嘗試了各種各樣的東西,但無法使其正常工作。 – user3732216