【问题标题】:GAE: Flask/webassets throws an expection on {% extends "base.html" %}GAE:Flask/webassets 在 {% extends "base.html" %} 上抛出异常
【发布时间】:2013-06-13 13:24:57
【问题描述】:

我正在尝试将现有的烧瓶应用程序移植到谷歌应用程序引擎中。经过大量阅读和解决问题后,我遇到了一个我完全陷入困境的问题:

在我的本地环境中启动应用程序时,我收到以下错误消息:

短版:

{% extends "base.html" %}
OSError: [Errno 38] Function not implemented

这个功能怎么能不实现呢?它是烧瓶/jinja2 的一部分。

加长版:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>
ERROR    2013-06-17 14:26:42,772 app.py:1306] Exception on / [GET]
Traceback (most recent call last):
  File "/home/kave/eclipse/F11/Engineering/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/kave/eclipse/F11/Engineering/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/kave/eclipse/F11/Engineering/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/kave/eclipse/F11/Engineering/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/kave/eclipse/F11/Engineering/f11_app/views.py", line 28, in index
    return render_template('index.html')
  File "/home/kave/eclipse/F11/Engineering/flask/templating.py", line 125, in render_template
    context, ctx.app)
  File "/home/kave/eclipse/F11/Engineering/flask/templating.py", line 107, in _render
    rv = template.render(context)
  File "/home/kave/eclipse/F11/Engineering/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/kave/eclipse/F11/Engineering/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/kave/eclipse/F11/Engineering/f11_app/templates/index.html", line 1, in top-level template code
    {% extends "base.html" %}
OSError: [Errno 38] Function not implemented
INFO     2013-06-17 14:26:42,799 server.py:593] default: "GET / HTTP/1.1" 500 291

知道这可能是什么吗?非常感谢

【问题讨论】:

  • 你能展示你的模板吗?看起来您使用了一些从模板上下文中不可见的功能
  • 我主要使用两个函数:经典的url_for -> &lt;script src="{{ url_for('static', filename='bootstrap/js/bootstrap.min.js') }}"&gt;&lt;/script&gt;Flask-Assets -> {% assets "f11_js" %} &lt;script type="text/javascript" src="{{ ASSET_URL }}"&gt;&lt;/script&gt; {% endassets %}
  • 我以前从未使用过资产,但快速谷歌搜索将我指向此模块 webassets.readthedocs.org/en/latest/integration/jinja2.html 确保您已在本地环境中安装。
  • @MikhailKashkin 这是正确的。我正在使用elsdoerfer.name/docs/flask-assets,它是网络资产的包装器。我想知道这是否允许/与 GAE 兼容。我认为这是不允许的,因为 Flask-Assets 需要在运行时缩小 javascripts。 GAE 不会/不允许这样做。所以我想知道GAE用户如何缩小他们的css和js?再次开始谷歌搜索... :)
  • 是的,你是对的。我必须报废它。你可以把这个作为答案,我打勾。现在我需要找到一种在 GAE 上自动缩小的好方法。谢谢

标签: google-app-engine flask webassets flask-assets


【解决方案1】:

出现此错误是因为 Jinja 不知道模板中使用的标签 assets。第二个问题是该项目应该使用webasset python 库在 GAE 上运行。但默认情况下它不起作用,因为webassets 需要输出文件夹来存储压缩的静态文件,这违反了 GAE 托管逻辑。

解决方法很简单:不要实时使用webassets,在上传到GAE之前压缩静态文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2011-05-25
    • 2015-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多