2

我有一个使用 Flask 的网站。主程序很长,所以我用粘贴来向您展示代码。当我使用它运行它时,./site serve --debug它可以完美运行,但我不能用 Flask-frozen 来冻结它。我有这个错误:

$ ./site build                       
Building website...
./site:240: MimetypeMismatchWarning: Filename extension of u'sitemap.xml' (type application/xml) does not match Content-Type: text/html; charset=utf-8
  freezer.freeze()
Traceback (most recent call last):
  File "./site", line 346, in <module>
    parser.dispatch()
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/helpers.py", line 53, in dispatch
    return dispatch(self, *args, **kwargs)
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 123, in dispatch
    for line in lines:
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 199, in _execute_command
    for line in result:
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/argh/dispatching.py", line 182, in _call
    result = args.function(*positional, **keywords)
  File "./site", line 240, in build
    freezer.freeze()
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 140, in freeze
    new_filename = self._build_one(url)
  File "/home/guillaume/nicolas.perriault.net/env/lib/python2.7/site-packages/flask_frozen/__init__.py", line 250, in _build_one
    % (response.status, url))
ValueError: Unexpected status '500 INTERNAL SERVER ERROR' on URL /403.html

如果我在site.py中删除关于403.html的部分,我有同样的错误404,然后是500,然后是contact.html,然后是/。我找不到原因。有没有人有想法?

4

1 回答 1

4

在冻结您的应用程序时启用测试。它应该产生更多关于错误的信息。

@command
def build():
    """ Builds this site.
    """
    print("Building website...")
    app.debug = False
    app.testing = True
    asset_manager.config['ASSETS_DEBUG'] = False
    freezer.freeze()
    local("cp ./static/*.ico ./build/")
    local("cp ./static/*.txt ./build/")
    local("cp ./static/*.xml ./build/")
    print("Done.")

Frozen-flask 使用app.test_client()查看它的文档

于 2013-07-18T12:58:01.907 回答