久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - flask template file not found

瀏覽:137日期:2022-06-28 09:16:03

問題描述

在同級(jí)目錄下,不明白為什么 index.html 和 視圖控制器沒有自動(dòng)綁定, 提示鴨子類型引起的,是哪里干擾了 視圖的綁定?python - flask template file not found

那這種,app和 temeplate 在同級(jí)目錄,路徑該如何寫?我 寫成 app =Flask(__name__,template_folder=’templates’),pycharm 左側(cè),并沒有提示 ,templates 綁定 html 的圖標(biāo)python - flask template file not found

問題解答

回答1:

默認(rèn)情況下模板是在同級(jí)目錄templates里的,你這個(gè)目錄沒有創(chuàng)建。

回答2:

這個(gè)主要原因是app在定義的時(shí)候,默認(rèn)是指向templates這個(gè)目錄中的,你應(yīng)該吧index.html放到rest1的templates目錄中。或者在app=Flask(__name__, template_folder=’path’), 指定路徑http://flask.pocoo.org/docs/0... 此為Flask API文檔

Parameters: import_name – the name of the application packagestatic_url_path – can be used to specify a different path for the static files on the web. Defaults to the name of the static_folder folder.static_folder – the folder with static files that should be served at static_url_path. Defaults to the ’static’ folder in the root path of the application.template_folder – the folder that contains the templates that should be used by the application. Defaults to ’templates’ folder in the root path of the application.instance_path – An alternative instance path for the application. By default the folder ’instance’ next to the package or module is assumed to be the instance path.instance_relative_config – if set to True relative filenames for loading the config are assumed to be relative to the instance path instead of the application root.root_path – Flask by default will automatically calculate the path to the root of the application. In certain situations this cannot be achieved (for instance if the package is a Python 3 namespace package) and needs to be manually defined.

要仔細(xì)閱讀文檔,里面有寫template_folder參數(shù)讀取的目錄是以root_path為準(zhǔn),你要理解每個(gè)參數(shù)的意義。

回答3:

pycharm 設(shè)置 Mark as template folder

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 都安| 岢岚县| 灌云县| 阿尔山市| 广昌县| 南昌县| 凤冈县| 桃源县| 东乌| 通城县| 宜丰县| 尚义县| 岳阳市| 邵武市| 敦煌市| 确山县| 永仁县| 睢宁县| 高要市| 乌鲁木齐县| 安塞县| 汪清县| 枝江市| 石嘴山市| 铁岭市| 利辛县| 苏州市| 金坛市| 涞水县| 侯马市| 延川县| 会理县| 营山县| 桐柏县| 临沂市| 常山县| 白河县| 莒南县| 南开区| 鹤岗市| 榆林市|