I get the following error when accessing a URL with Flask-Assets which is supposed to render and minify css.
ERROR 2016-09-01 02:45:00,096 app.py:1587] Exception on /SomeFile [GET]
Traceback (most recent call last):
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/vinay/App-Engine/zion-alpha/app/routes/home_routes.py", line 14, in show_file
return render_template('main.html')
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/templating.py", line 134, in render_template
context, ctx.app)
File "/Users/vinay/App-Engine/zion-alpha/lib/flask/templating.py", line 116, in _render
rv = template.render(context)
File "/Users/vinay/App-Engine/zion-alpha/lib/jinja2/environment.py", line 989, in render
return self.environment.handle_exception(exc_info, True)
File "/Users/vinay/App-Engine/zion-alpha/lib/jinja2/environment.py", line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/zion-alpha/app/templates/main.html", line 6, in top-level template code
{% assets "css_all" %}
OSError: [Errno 78] Function not implemented
INFO 2016-09-01 02:45:00,116 module.py:788] default: "GET /SomeFile HTTP/1.1" 500 291
INFO 2016-09-01 02:45:00,853 module.py:402] [default] Detected file changes:
/Users/vinay/App-Engine/zion-alpha/app
The following is the code containing Flask-Assets
def create_app():
"""Create the Flask App"""
app = Flask(__name__)
configure_blueprints(app)
css = Bundle('css/main.css',
'css/main2.css',
filters="cssmin",
output="static/css/min.css"
)
assets = Environment(app)
assets.register('css_all', css)
return app
HTML
{% assets "css_all" %}
<link rel="stylesheet" href="{{ ASSET_URL }}"/>
{% endassets %}
Folder structure
.
├── admin
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── routes
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── admin_routes.py
│ │ └── admin_routes.pyc
│ ├── static
│ │ └── css
│ │ ├── admin-2.css
│ │ └── admin.css
│ └── templates
│ └── adminindex.html
├── app
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── routes
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── home_routes.py
│ │ └── home_routes.pyc
│ ├── static
│ │ └── css
│ │ ├── main.css
│ │ └── main2.css
│ └── templates
│ └── main.html
├── app.yaml
├── appengine_config.py
├── appengine_config.pyc
4 directories, 9 files
This seems to be a problem with
flask-assetsand Google App Engine because GAE disallows file creation at run-time.Possible duplicate of: GAE: Flask/webassets throws an expection on {% extends "base.html" %}
Either minify the css before deploying to GAE, or find a different method of serving the minified css either at runtime (not preferred) or buildtime (preferred).
One possibility is to create the minified js on the first run (buildtime), which can then be uploaded to a google storage bucket.
Another option is to create the minified js at runtime and keep it stored in a memcache.