#安裝 pip install flask from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run()
app = Flask(__name__) # 這是實例化一個Flask對象,最基本的寫法 # 可是Flask中還有其餘參數,如下是可填的參數,及其默認值 def __init__(self, import_name,static_url_path=None, static_folder='static', template_folder='templates', instance_path=None, instance_relative_config=False, root_path=None):
app = Flask(__name__,template_folder='templates',static_url_path='/xxxxxx')
如:在根目錄下建立目錄,templates和static,則return render_template時,能夠找到裏面的模板頁面;如在static文件夾裏存放11.png,在引用該圖片時,靜態文件地址爲:/xxxxxx/11.pngflask