简体   繁体   中英

Flask render_template where HTML is in S3

Can I have templates stored in S3 send to render_template ?

application_root = config.get_application_root()
static_folder = os.path.join(application_root, 'static')
template_folder = os.path.join(application_root, 'templates')
app = Flask(__name__, static_url_path='/static', static_folder=static_folder, template_folder=template_folder)

Easy solution would be to download s3 objects to a server directory and point render_template to pick from that directory.

I am wondering if this intermediate step is ever required. I have web_content passed down as pre-built HTML files and do not generate them. Can I send HTML as a string to render_template without actually having a HTML file?

/flask_folder 
----/app.py
----/templates/
----/static/

/my_external_template_folder

Use render_template_string instead of render_template :

http://flask.pocoo.org/docs/1.0/api/#flask.render_template_string

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM