We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using flask-caching together with Flask's stream_template, JSON is produced rather than HTML.
Is this expected and am I missing something? I searched the docs but did not find mention of stream_template.
EDIT: It seems that render_template() returns an iterator which gets then retrieved as an array but upon retrieval it's not converted back
The issue is reproducible with:
To reproduce the issue:
Create a file app.py containing the following code
#! /usr/bin/env python3 from flask import Flask, render_template, stream_template from flask_caching import Cache config = { #"CACHE_TYPE": "RedisCache", # Flask-Caching related configs #"CACHE_TYPE": "SimpleCache", # Flask-Caching related configs "CACHE_TYPE": "NullCache", # Flask-Caching related configs "CACHE_DEFAULT_TIMEOUT": 300, "CACHE_REDIS_URL" : "unix:///var/run/redis/redis.sock" } app = Flask(__name__) # tell Flask to use the above defined config app.config.from_mapping(config) cache = Cache(app) @app.route("/") @cache.cached() def index(): return render_template('index.html') @app.route("/stream") def stream(): return stream_template('index.html') @app.route("/stream-cached") @cache.cached() def stream_cached(): return stream_template('index.html') if __name__ == '__main__': counter = 0 app.run()
Create a file templates/index.html with the following content
templates/index.html
<html> <body> <p> Hello World! </p> </body> </html>
Run the app with python3 app.py
python3 app.py
Expected behaviour is to obtain from all routes the following:
What happens insetead is that both / and /stream produce expected output while /stram-cached produces the following:
/
/stream
/stram-cached
[ "<html>\n <body>\n <p>\n Hello World!\n </p>\n </body>\n</html>" ]
Environment:
$ python --version Python 3.11.3
$ pip freeze blinker==1.6.2 cachelib==0.9.0 click==8.1.6 Flask==2.3.2 Flask-Caching==2.0.2 itsdangerous==2.1.2 Jinja2==3.1.2 MarkupSafe==2.1.3 redis==4.6.0 Werkzeug==2.3.6
The text was updated successfully, but these errors were encountered:
No branches or pull requests
When using flask-caching together with Flask's stream_template, JSON is produced rather than HTML.
Is this expected and am I missing something? I searched the docs but did not find mention of stream_template.
EDIT: It seems that render_template() returns an iterator which gets then retrieved as an array but upon retrieval it's not converted back
The issue is reproducible with:
To reproduce the issue:
Create a file app.py containing the following code
Create a file
templates/index.html
with the following contentRun the app with
python3 app.py
Expected behaviour is to obtain from all routes the following:
What happens insetead is that both
/
and/stream
produce expected output while/stram-cached
produces the following:Environment:
The text was updated successfully, but these errors were encountered: