Flask

How to hold Plotly dash app behind protected route

此生再无相见时 提交于 2021-02-04 18:17:25
问题 I have a plotly dash app which I would like to hold behind a route that is protected with a JWT. My end goal is to contain this in an iframe on a separate route, but I only want the user to be able to get the html of th dash app if they have an access token. I have retried returning the app itself in a get request. App.py import dash from flask import Flask, jsonify, request from flask_jwt_extended import ( JWTManager, jwt_required, create_access_token, get_jwt_identity ) server = Flask(_

How do I call a database function using SQLAlchemy in Flask?

非 Y 不嫁゛ 提交于 2021-02-04 15:13:28
问题 I want to call a function that I created in my PostgreSQL database. I've looked at the official SQLAlchemy documentation as well as several questions here on SO, but nobody seems to explain how to set up the function in SQLAlchemy. I did find this question, but am unsure how to compile the function as the answer suggests. Where does that code go? I get errors when I try to put this in both my view and model scripts. Edit 1 (8/11/2016) As per the community's requests and requirements, here are

Flask: where to put static javascript files in templates

╄→尐↘猪︶ㄣ 提交于 2021-02-04 15:08:39
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

Flask: where to put static javascript files in templates

房东的猫 提交于 2021-02-04 15:08:24
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

Flask: where to put static javascript files in templates

余生颓废 提交于 2021-02-04 15:07:46
问题 I'm developing a flask app with the following folder structure: |-->flask_app.py |-->static |-->css |-->bootstrap.min.css |-->styles.css |-->js |-->jquery-3.1.1.min.js |-->bootstrap.min.js |-->script.js |-->templates |-->index.html What is the proper way to link to these css and js files in index.html and what parameters do I need associated with them? My CSS links look like this and are located in the header: <link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">

List files in directories with flask

我怕爱的太早我们不能终老 提交于 2021-02-04 11:44:21
问题 I’d like to list the files which are in directories and subdirectories. I have used this answer to have the list, but the items are non-clickables, so I’d like to add a link between the name of the files and their locations. I have try to modify the template with something like this : <!doctype html> <title>Path: {{ tree.name }}</title> <h1>{{ tree.name }}</h1> <ul> {%- for item in tree.children recursive %} <li><a href="{{ item.name }}">{{ item.name }}</a> {%- if item.children -%} <ul><a

How to set cookie in Python Flask?

╄→гoц情女王★ 提交于 2021-02-04 09:10:48
问题 In this way, I want to set my cookie. But it fails to set. @app.route('/') def index(): res = flask.make_response() res.set_cookie("name", value="I am cookie") When I print res it shows <Response 0 bytes [200 OK] But not set cookie 回答1: You have return the response after set the cookie. @app.route('/') def index(): resp = make_response(render_template(...)) resp.set_cookie('somecookiename', 'I am cookie') return resp This way cookie will generate in your browser but you can get this cookie in

How to set cookie in Python Flask?

﹥>﹥吖頭↗ 提交于 2021-02-04 09:10:38
问题 In this way, I want to set my cookie. But it fails to set. @app.route('/') def index(): res = flask.make_response() res.set_cookie("name", value="I am cookie") When I print res it shows <Response 0 bytes [200 OK] But not set cookie 回答1: You have return the response after set the cookie. @app.route('/') def index(): resp = make_response(render_template(...)) resp.set_cookie('somecookiename', 'I am cookie') return resp This way cookie will generate in your browser but you can get this cookie in

Why does my Flask app not render CSS if I don't clear my cache?

我是研究僧i 提交于 2021-02-04 08:36:27
问题 I've been using Flask and have linked the html I'm rendering to a css stylesheet. I've noticed that whenever I update my CSS code, I have to clear the cache in order to get it to update on the webpage. How can I fix this? 回答1: I assume you are loading your CSS files with something like: {{ url_for('static', filename='some/file.css') }} For this to refresh immediately in development, you should set the following config var to -1 : app.config['SEND_FILE_MAX_AGE_DEFAULT'] = -1 As @Matvei states,

Why does my Flask app not render CSS if I don't clear my cache?

强颜欢笑 提交于 2021-02-04 08:35:06
问题 I've been using Flask and have linked the html I'm rendering to a css stylesheet. I've noticed that whenever I update my CSS code, I have to clear the cache in order to get it to update on the webpage. How can I fix this? 回答1: I assume you are loading your CSS files with something like: {{ url_for('static', filename='some/file.css') }} For this to refresh immediately in development, you should set the following config var to -1 : app.config['SEND_FILE_MAX_AGE_DEFAULT'] = -1 As @Matvei states,