Flask

Dropdown menu from Python list using Flask and HTML

[亡魂溺海] 提交于 2021-02-08 08:52:18
问题 I am creating a dropdown menu in HTML using info from a python script. I have inspired myself from this StackOverflow question: How to create dropdown menu from python list using Flask and HTML However, when I try to retrieve back the selected answer, I get (also tried with 'colour' and gave me the same problem): select = request.form.get(colours) NameError: name 'colours' is not defined This is my __init__.py which is the main of my Flask application, and I have this route inside which is

Flask - detect disconnection

元气小坏坏 提交于 2021-02-08 08:43:22
问题 Is there any way to detect when the user close/refresh the web? My program look something like this: @app.route('/') def form(): return render_template('form_ConfusionSet_submit.html') @app.route('/hello/', methods=['GET','POST']) def hello(): some action... return render_template('form_action.html', text=text) @app.route('/add/', methods=['POST']) def add(): some action... return render_template('form_text_submit.html',USER = USER) I need to delete some files from the server when the user

How to use many-to-many fields in Flask view?

独自空忆成欢 提交于 2021-02-08 08:37:56
问题 I am trying to create a blog using Flask. Every post can have multiple tags also every tag could be associated with multiple posts. So I created a many-to-many relationship. My questions is how do i save multiple tags when creating a new post. And since every post can have different number of tags how do i show this is in the form? Also, how can i create new tags along with the post and then use those tags with other posts? This is models.py - postcategory = db.Table('tags', db.Column('posts

How to use many-to-many fields in Flask view?

亡梦爱人 提交于 2021-02-08 08:36:11
问题 I am trying to create a blog using Flask. Every post can have multiple tags also every tag could be associated with multiple posts. So I created a many-to-many relationship. My questions is how do i save multiple tags when creating a new post. And since every post can have different number of tags how do i show this is in the form? Also, how can i create new tags along with the post and then use those tags with other posts? This is models.py - postcategory = db.Table('tags', db.Column('posts

Python Flask PUT and DELETE Methods when submitting HTML Form

匆匆过客 提交于 2021-02-08 08:20:20
问题 I have 2 forms on an HTML page with the same action URL (e. g. action = "/example"). In my Python Flask .py file, I have 2 routes with the same url, but I want 1 route to have the PUT method and the other to have the DELETE method (e. g. @app.route('/example'), methods=['PUT'] vs. @app.route('/example'), methods=['DELETE']). How can I do that? I have visited multiple websites and some examples I have seen include using jQuery or hidden inputs (e. g. ), but so far, these examples do not work.

Python Flask PUT and DELETE Methods when submitting HTML Form

会有一股神秘感。 提交于 2021-02-08 08:20:12
问题 I have 2 forms on an HTML page with the same action URL (e. g. action = "/example"). In my Python Flask .py file, I have 2 routes with the same url, but I want 1 route to have the PUT method and the other to have the DELETE method (e. g. @app.route('/example'), methods=['PUT'] vs. @app.route('/example'), methods=['DELETE']). How can I do that? I have visited multiple websites and some examples I have seen include using jQuery or hidden inputs (e. g. ), but so far, these examples do not work.

Heroku (Python/Flask) web app truncating log messages to only one line

有些话、适合烂在心里 提交于 2021-02-08 08:15:17
问题 I have a simple Python/Flask web that contains this: @app.route('/index') def index(): app.logger.warning('test message 1\ntest message 2\ntest message 3') Note the newline characters. When I run it with heroku local web I see this in the logs: web.1 | WARNING:app:test message 1 But when I push it to heroku instead of running it locally I see: 2015-12-09T22:23:21.102478+00:00 app[web.1]: WARNING in app[/app/app.py:17]: test message 1 2015-12-09T22:23:21.102482+00:00 app[web.1]: test message 2

Heroku (Python/Flask) web app truncating log messages to only one line

心已入冬 提交于 2021-02-08 08:14:41
问题 I have a simple Python/Flask web that contains this: @app.route('/index') def index(): app.logger.warning('test message 1\ntest message 2\ntest message 3') Note the newline characters. When I run it with heroku local web I see this in the logs: web.1 | WARNING:app:test message 1 But when I push it to heroku instead of running it locally I see: 2015-12-09T22:23:21.102478+00:00 app[web.1]: WARNING in app[/app/app.py:17]: test message 1 2015-12-09T22:23:21.102482+00:00 app[web.1]: test message 2

Running Flask app with uwsgi and nginx

故事扮演 提交于 2021-02-08 08:09:22
问题 I am following the digital ocean tutorial for configuring nginx uwsgi to serve flask application. Digital Ocean Tuttorial link I have made the service for starting my application.But when i run it, i get the following status Process: 726 ExecStart=/home/user/app/my_project/venv/bin/uwsgi --ini my_project.ini (code=exited, status=217/USER) myproject.ini contains configuration for running uwsgi [uwsgi] module = wsgi master = true processes = 5 socket = myproject.sock chmod-socket = 660 vacuum =

Flask: How To Prevent Replay Attacks

做~自己de王妃 提交于 2021-02-08 07:57:59
问题 I'm trying to implement a logic in my Flask application to prevent reply attacks. Regarding to the question asked here, My idea is to set the current session lifetime when user logs out from the system. In general, it is suggested to set the session lifetime this way: @app.before_request def before_request(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=10) However, I want to set my current session life time when user logs out from the system. Something like the