Flask

In a flask function which returns `send_file`, the code doesn't appear to run on subsequent requests, yet the file still downloads. Why?

北慕城南 提交于 2021-02-05 09:55:28
问题 I am using a Flask Code with the following route: @app.route('/download') def download_file(): path = "certificate.docx" print("certificate printed") print(os.getcwd()) return send_file(path, as_attachment=True) HTML Code: <p> <a href="{{ url_for('.download_file') }}">Download</a> </p> This piece of code is being executed to download a file named certificate.docx . The problem is that the print statements inside the function download_file() are not actually being executed, yet it still allows

RuntimeError: There is no current event loop in thread 'Thread-1' in flask

拥有回忆 提交于 2021-02-05 09:46:33
问题 I want to run a asynchronous event in background with flask and for that i worte a code below But When I run app.py main function is successfully run for the first time by the schedule but in second time it throwing an error. Please give me a solution main.py import asyncio import aiohttp from database import DBHelper MESSAGE_TO_SEND = 'Please Complete Your Task' ACCESS_TOKEN = Access_token db = DBHelper() async def taskReminder(memberID): data = { "recipient": { "id": memberID }, "message":

Browser blocking Mathjax on app engine static page

不打扰是莪最后的温柔 提交于 2021-02-05 09:27:09
问题 I am trying to serve a static page containing Tex-style Math that is to be rendered by Mathjax. The pages are being served by a Flask app on Google app engine. Problem is - Chrome, Opera and Edge - all browsers are blocking Mathjax from rendering the Math, but it works properly if I manually unblock it from on top of the browser every time the page loads. The site works perfectly offline, but the problem occurs when the page is accessed through the app engine app. Any way to prevent the

How to close webview and get json response in flask?

为君一笑 提交于 2021-02-05 09:24:27
问题 I want to close my selectGroupView after getting response when I click on submit button. Currently I am not getting any response as my selectGroupView is closing suddenly whenever I click on submit button. Actually I want to return a json data after submission of a form. So that I can use it further. Please Help me. app.py from flask import Flask, request,render_template @app.route('/select-group/<string:assignerID>',methods=['GET']) def selectGroupView(assignerID): assignerInfo = info

how left outer join in sqlalchemy?

为君一笑 提交于 2021-02-05 09:21:58
问题 I want implement left outer join in sqlalchemy. the sql query is like this: select * from skills left join user__skill on user__skill.skill_id=skills.id and user__skill.user_id=4 and what i wrote in sqlalchemy is : skills = db.session.query(Skill, User_Skill.skill_id).\ outerjoin(User_Skill, User_Skill.skill_id==Skill.id and User_Skill.user_id==4).\ order_by(Skill.name).all() but it doesn't filter for a user and show all users skills. how can i write this code? 回答1: EDIT: Use and_ from

[Flask]-Customising Flask-user login

非 Y 不嫁゛ 提交于 2021-02-05 08:55:49
问题 Have been working on Flask-user for the user management system, But I couldn't see a way to customise the login page and registration page. I installed flask-user using pip pip install flask-user Any help would be appreciated 回答1: In templates folder, create a new folder named flask_user and you can copy the login.html and register.html pages used by flask-user to the newly created folder. Then you can modify them as per your requirements. These files will override the pages used by flask

how to carry string with spaces through a HTML form, using Flask

牧云@^-^@ 提交于 2021-02-05 07:17:25
问题 I'm trying to build a simple online quiz using Flask and Python 3.6, using HTML forms with radio buttons to carry the selected answers between Flask routes. The first step is to select a category for the quiz, before leading to the actual quiz page, as follows: app = Flask(__name__) categories = ['Europe', 'South America', 'North America'] @app.route('/') def select(): return render_template('selecting.html', cats= categories) @app.route('/quiz', methods = ['POST']) def quizing(): selected

Flask: How to avoid generate any kind of answer for a specific URL

孤者浪人 提交于 2021-02-05 06:52:10
问题 I am programming a home Web server for home automation. I've seen several times 'bots' scanning the ports of my server. To avoid give any kind of activity signs to undesired scans, I'm trying to avoid generate any kind of answer for specific URLs, like '/', ie. configure a silent mode for the typical scanned URL's. I've tried with void .route decorators, error addressing and void pages, but all of them generated some kind of response. It's that possible in Flask with Python? Any workaround?

Django 与 Flask框架的比较

荒凉一梦 提交于 2021-02-05 04:42:51
Django Django恐怕是最有代表性的Python框架了。它是一个遵循MMVC架构模式的开源框架。它的名字来自Django Reinhardt,一个法国作曲家和吉他演奏家,很多人认为他是历史上最伟大的吉他演奏家。位于堪萨斯洲的Lawrence城的Lawrence Journal-World报社有两位程序员,Adrian Holovaty和Simon Willison,他们在2003的时候开发出了Django,用于给报纸开发web程序。 Django内置了模板引擎,同时也通过OOTB来支持流行的Jinja2引擎。它还支持基于正则的URL分发,可以通过简单的URL来完成复杂的映射。 Django的优势之一是只需要单独的安装包来安装。其他的一些类似的框架需要下载很多组件才能开始工作。而且,Django还有完善的保持更新的文档,对于开源项目来说这通常是短板。它是一个健壮的框架,很好的集成了很多来自社区的插件和扩展。项目背后的社区看上去也组织的很好,这从它非常完善的文档和教程就可以看出来。 Flask Flask是一个基于Jinja2和Werkzeug的python微框架,和其他框架类似,它是BSD授权的,一个有少量限制的免费软件许可。使用Flask的网站包括领英LinkedIN和Pinterest。Flask有以下特点: 内建的单元测试支持 模板使用Jinjia2 大量文档

Proxy a GET request to a different site in Python

狂风中的少年 提交于 2021-02-04 20:57:39
问题 I want to forward a GET request that I get from a client to a different site, In my case- A m3u8 playlist request to a streaming site to handle. Does anyone know how can it be done? 回答1: If you want to proxy, first install requests : pip install requests then, get the file in the server and serve the content, ej: import requests from flask import Flask, Response app = Flask(__name__) @app.route('/somefile.m3u') def proxy(): url = 'https://www.example.com/somefile.m3u' r = requests.get(url)