【Python】Learn Python the hard way, ex50 第一個網站
阿新 • • 發佈:2019-01-06
利用lpthw.web框架實現"Hello World"網頁版,程式碼如下:
import web urls = ('/', 'index') app = web.application(urls, globals()) render = web.template.render('templates/') class Index: def GET(self): greeting = 'Hello World' return render.index(greeting = greeting) if __name__ == '__main__': app.run()
另外,在templates資料夾內建立index.html模板檔案,渲染文字,最終輸出入下圖所示
index.html內容如下:
$def with (greeting) <html> <head> <title>Gothons Of Planet Percal #25</title> </head> <body> $if greeting: I just wanted to say <em style='color: green; font-size:2em;'>$greeting </em>. $else: <em>Hello</em>, world! <body> </html>