构建我的静态站点(使用Flask freeze来冻结Flask应用程序)效果很好,但当我试图用
python -m cProfile athena.py
,我得到了错误
PermissionError:[Errno 13]权限被拒绝:
“/Library/Developer/CommandLineTools/Library/Frameworks/Python3。framework/Versions/3.8/lib/python3。8/建造
ie Freeze Flask正试图在我的系统上的python主文件夹中创建其构建文件夹,而不是在我当前的工作目录中。(即使我使用的是venv!
which python
产量
/path/to/dir/bin/python
.)
通过使用硬编码的根路径实例化我的Flask应用程序,我能够绕过这个问题:
athena = Flask(__name__, root_path='/path/to/dir')
但我得到了一个错误:
MissingURLGeneratorWarning:端点页面未冻结任何内容,
硬链接。你忘了URL生成器了吗?
试图用调试器缩小问题范围,我明白了
pages
在分析时生成一个空列表,在常规模式下生成一个页面列表,这让我怀疑索引没有生成,或者是在其他地方生成的。
此外,我的观点也有一些不同
config
(这是从
__name__
):
分析配置:“调试”:False,“FLATPAGES_AUTO_RELOAD”:“if DEBUG”,
“FLATPAGES_EXTENSION”:”。html'
常规配置:“调试”:True,
“FLATPAGES_AUTO_RELOAD”:True,“FLATPAGES_EXTENSION”:。md',
“冷冻库库库URL”:http://localhost/“,“冷冻库删除额外文件”:
错误的
以下是我代码的要点(完整代码如下)
here
):
from flask import Flask, render_template
from flask_flatpages import FlatPages
from flask_frozen import Freezer
from flask_static_compress import FlaskStaticCompress
DEBUG = True
FLATPAGES_AUTO_RELOAD = DEBUG
FLATPAGES_EXTENSION = ".md"
FREEZER_REMOVE_EXTRA_FILES = False
FREEZER_BASE_URL = "http://localhost/"
athena = Flask(__name__)
athena.config.from_object(__name__)
pages = FlatPages(athena)
freezer = Freezer(athena)
@athena.route("/")
def index():
posts = [page for page in pages if "ispage" not in page.meta]
hpages = [page for page in pages if "ispage" in page.meta]
return render_template(
"index.html", pages=posts, hpages=hpages)
@athena.route("/<path:path>/")
def hardpagelink(path):
hpage = ""
for page in pages:
if page.path == path:
if page.meta["ispage"]:
hpage = page
hpages = [page for page in pages if "ispage" in page.meta]
return render_template("hard.html", page=hpage, hpages=hpages)
@athena.route("/posts/<path:path>/")
def page(path):
page = pages.get_or_404(path)
hpages = [page for page in pages if "ispage" in page.meta]
return render_template("page.html", page=page, hpages=hpages)
if __name__ == "__main__":
freezer.freeze()
如果有人想重现这一点,以下是设置env的说明:
git clone https://github.com/lordgrenville/athena.git
cd athena/
brew install jez/formulae/pandoc-sidenote
# or cabal install pandoc-sidenote
npm install -g less
python3 -m venv blogenv/ && source blogenv/bin/activate
pip install werkzeug pypandoc virtualenv flask-flatpages frozen-flask pandoc-crossref flask-static-compress feedgen
python athena.py build
python -m cProfile athena.py build # fails