Flask

Running Flask via FastCGI in IIS at application level instead of website leve

走远了吗. 提交于 2021-02-11 12:34:06
问题 I've configured the basic Flask web sample in a VENV and now it is correctly published through IIS via FastCGI. Well, here it is my trivial sample00.py from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello, World, from Flask!" and the web.config, a little more involved: <?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers> <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="F:\Appl\flask\venv

Flask WTForms BooleanField UnboundField

风格不统一 提交于 2021-02-11 12:32:22
问题 I am writing a script that normally retrieves 5 lines from the database and I want to display it as a checkbox list. But it doesn't display correctly: it says " UnboundField " form.py class ExampleForm(FlaskForm): [...query & results...] for line in results_sql: list_checkbox[line.label] = BooleanField(line.label) routes.py @bp.route('/example') def example(): form = ExampleForm() return render_template("index.html", form=form) index.html <table class="table table-bordered table-condensed"> {

Python Flask: Return MCQ output, with right and chosen answers highlighted

泪湿孤枕 提交于 2021-02-11 12:20:37
问题 I have this flask app: import os import random from flask import Flask, render_template, request app = Flask(__name__) quiz_host = os.environ.get('FLASK_HOST') quiz_port = os.environ.get('FLASK_PORT') questions = [{'id':1, 'question':'what is 2 + 3','correct':'2','choices':['1','2','3',5']}, {'id':2,'question':'what is 4 + 6',correct':'10','choices':['10','11','12','13']}] @app.route("/quiz", methods=['POST', 'GET']) def quiz(): if request.method == 'GET': return render_template("index.html",

How to execute PyQt5 application on a resful call

▼魔方 西西 提交于 2021-02-11 09:58:44
问题 Context: I have a Flask application serving a resource POST /start . The logic to be executed involves a PyQt5 QWebEnginePage loading a URL and returning certain data about it. Problem: When the QApplication is executed (calling app.exec_() ) I get the warning: WARNING: QApplication was not created in the main() thread. and then the error: 2019-07-17 13:06:19.461 Python[56513:5183122] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs

How to execute PyQt5 application on a resful call

笑着哭i 提交于 2021-02-11 09:58:16
问题 Context: I have a Flask application serving a resource POST /start . The logic to be executed involves a PyQt5 QWebEnginePage loading a URL and returning certain data about it. Problem: When the QApplication is executed (calling app.exec_() ) I get the warning: WARNING: QApplication was not created in the main() thread. and then the error: 2019-07-17 13:06:19.461 Python[56513:5183122] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs

How to execute PyQt5 application on a resful call

南笙酒味 提交于 2021-02-11 09:56:10
问题 Context: I have a Flask application serving a resource POST /start . The logic to be executed involves a PyQt5 QWebEnginePage loading a URL and returning certain data about it. Problem: When the QApplication is executed (calling app.exec_() ) I get the warning: WARNING: QApplication was not created in the main() thread. and then the error: 2019-07-17 13:06:19.461 Python[56513:5183122] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /BuildRoot/Library/Caches/com.apple.xbs

check for None in an array in flask (jinja template)

人盡茶涼 提交于 2021-02-11 09:40:09
问题 I have a weird situation where array has value as None: 'synonyms': [None] The json format of data in mongo is as: { "_id": { "$oid": "5e0983a63bcf0dab51f32a9d" }, "word": "vulgarizer", "wordset_id": "c0c349060a", "labels": [{ "name": "American", "is_dialect": true }], "meanings": [{ "id": "3cb39b55e5", "def": "someone who makes attractive to the general public", "speech_part": "noun", "synonyms": ["populariser"] }, { "id": "865bfdea0b", "def": "someone who makes something vulgar", "speech

Extend a blueprint in Flask, splitting it into several files

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 08:43:49
问题 In flask, I have a blueprint that is getting a bit too long and I'd like to split it into several files, using the same route /games I tried extending the class, but it doesn't work? # games.py from flask import Blueprint bp = Blueprint('games', __name__, url_prefix='/games') @bp.route('/') def index(): ... . # games_extend.py from .games import bp @bp.route('/test') def test_view(): return "Hi!" Am I doing something wrong or is there a better way? 回答1: You can make it work using absolute

flask from app import db ImportError: cannot import name ‘db’ 的解决方案

扶醉桌前 提交于 2021-02-11 06:55:42
flask from app import db ImportError: cannot import name ‘db’ 的解决方案 参考文章: (1)flask from app import db ImportError: cannot import name ‘db’ 的解决方案 (2)https://www.cnblogs.com/weigege2015/p/9321273.html 备忘一下。 来源: oschina 链接: https://my.oschina.net/u/4438370/blog/4952281

Flask URL routing : url_for only passes first argument

 ̄綄美尐妖づ 提交于 2021-02-11 05:16:21
问题 I have jQuery tabbed panel that loads pages within the tab on click. This works fine. What I want now is to pass additional arguments to the url such as the title of the tab being clicked. The script to load is the following: $(document).ready(function(){ $( "#content" ).load( "{{url_for(xyz, query=query)}}" ); var tabs = $('.tabs > li'); tabs.on("click", function(){ tabs.removeClass('active'); $(this).addClass('active'); $( "#content" ).load( "{{url_for(xyz, query=query)}}" ); }) }); The