Flask

Return multiple image files with Flask

谁说我不能喝 提交于 2021-02-18 07:59:32
问题 First I've searched a lot and didn't find a straight forward answer to my question yet. I'm writing a new program which accepts an image and then find similar images to it and then extract image names from a database. I've created a simple response with the name of these image files as a JSON format with Flask in python3. I need to display these images with its name under it as a web page with a response in Flask. The major problem is the number of images are not fixed and may vary, sometimes

Periodic “Lost connection to MySQL server during query” after Dockerizing Flask Web App

主宰稳场 提交于 2021-02-18 06:37:40
问题 I have a Flask web app that used to run on a standalone server using the following: Flask/SQLAlchemy MariaDB uwsgi nginx On the stand alone server this application ran fine. I have since "dockerized" this application across two containers: uwsgi-nginx-flask MariaDB Every since dockerizing I occasionally get this error (entire traceback posted at the end): Lost connection to MySQL server during query The MariaDB log shows the following errors with verbose logging: 2020-05-10 18:35:32 130

New to flask and Flask-Login - ImportError: No module named login

﹥>﹥吖頭↗ 提交于 2021-02-18 04:54:38
问题 It appears that installation of flask-login has issues. Despite a successful install using the below pip install flask-login My app.py file: from flaskext.login import LoginManager lm = LoginManager() I get this error : ImportError: No module named login So how do I resolve 回答1: There was a transition of the flask extension import way: Instead we now recommend naming packages flask_foo instead of the now deprecated flaskext.foo . Flask 0.8 introduces a redirect import system that lets uses

New to flask and Flask-Login - ImportError: No module named login

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-18 04:53:59
问题 It appears that installation of flask-login has issues. Despite a successful install using the below pip install flask-login My app.py file: from flaskext.login import LoginManager lm = LoginManager() I get this error : ImportError: No module named login So how do I resolve 回答1: There was a transition of the flask extension import way: Instead we now recommend naming packages flask_foo instead of the now deprecated flaskext.foo . Flask 0.8 introduces a redirect import system that lets uses

New to flask and Flask-Login - ImportError: No module named login

匆匆过客 提交于 2021-02-18 04:53:30
问题 It appears that installation of flask-login has issues. Despite a successful install using the below pip install flask-login My app.py file: from flaskext.login import LoginManager lm = LoginManager() I get this error : ImportError: No module named login So how do I resolve 回答1: There was a transition of the flask extension import way: Instead we now recommend naming packages flask_foo instead of the now deprecated flaskext.foo . Flask 0.8 introduces a redirect import system that lets uses

Django+Nginx+uwsgi搭建自己的博客(一)

陌路散爱 提交于 2021-02-18 03:32:02
最近对写爬虫有些厌倦了,于是将方向转移到了Web开发上。其实在之前自己也看过一部分Flask的资料,但总觉得Flask的资料有些零散,而且需要的各种扩展也非常多。因此,我将研究方向转移到了另一个主流的框架——Django上。 与Flask框架相比,Django框架提供了更全面的文档支持,其初始教程也很容易上手。而且,相比Flask,Django并不需要很多扩展的支持,其自身就提供了很多便利的类。个人感觉这两点使得学习Django比学习Flask更容易上手。 目前,Python3已经成为了主流版本,因此此文采用Python3.5进行开发。 环境:Ubuntu16.04+Python3.5 首先看一下目前的成果: 首页列出了当前所有博客的列表,包括作者,阅读量以及发表时间;在页面左上角是用户名以及该用户的头像,而右边可以退出登录以及发表博文。 点击博文,可以浏览到博文内容,以及发表评论并查看评论。 点击已注册的用户名,可以查看到该用户的相关资料。 下面来介绍Django的几个基本概念:Project, App, Model, View Project和App: 一个Django project即是一个网站,而App可以看为网站中的子功能。一个project里可以包含多个App,通过这些App的共同作用来实现网站的功能。 Model: 即数据库表模型

Python之Flask项目开发【入门必学】

Deadly 提交于 2021-02-17 23:49:41
前言 本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理。 作者:藤藤菜丶 Flask 安装Flask模块 创建一个Flask项目 运行Flask 运行参数 在网页页面中进行控制台调试 Flask 安装Flask模块 pip install flask 1 创建一个Flask项目,当然如果你python基础还没学好,是不能学flask的。建议先去小编的Python交流.裙 :一久武其而而流一思(数字的谐音)转换下可以找到了,里面有最新Python教程项目可拿, 只有学好python基础才能学flask,不能跳级! 创建一个app.py文件 from flask import Flask # 导入Flask包 app = Flask(__name__) # 获取Flask对象,以当前模块名为参数 # 路由默认为(127.0.0.1:5000) @app.route('/') # 装饰器对该方法进行路由设置,请求的地址 def hello_world (): # 方法名称 return 'Hello World!' # 返回响应的内容 if __name__ == '__main__': app.run() 运行Flask 通过python 执行app.py文件 python app.py 1 服务会默认的起在127.0

小伙Python爬虫并自制新闻网站,太好玩了

空扰寡人 提交于 2021-02-17 20:43:09
作者 : 豆腐 来源:凹凸数据 大家好,我又来了, 我是银牌厨师豆腐! 我们总是在爬啊爬,爬到了数据难道只是为了做一个词云吗? 当然不!这次我就利用flask为大家呈现一道小菜。 Flask是python中一个轻量级web框架,相对于其他web框架来说简单,适合小白练手。使用Flask+爬虫,教大家如何实时展示自己爬下来的数据到网页上。 先给大家展示一下这个丑丑的网页 ↓ (给个面子,别笑 ) 演示三个功能 整个流程就是简单的三步: 爬取数据 利用实时爬取数据生成词云 利用热点推荐新闻 爬虫部分: 这次爬虫主要利用多线程方式爬取新浪新闻+网易新闻所有栏目新闻信息。 一共14个栏目,两个网站的页面信息都是通过ajax加载完成的,请求对应的栏目链接后,返回的字符串是这样的,仔细观察会发现我们要看的新闻内容被包含在 data_callback 里面 图2 是一个列表样式, 这时候我们就可以用 eval 函数将这个字符串处理成一个列表格式 def get_wy_teach () : url = 'https://tech.163.com/special/00097UHL/tech_datalist.js?callback=data_callback' headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)

Running as a host user within a Docker container

有些话、适合烂在心里 提交于 2021-02-17 15:13:32
问题 In my team we use Docker containers to locally run our website applications while we do development on them. Assuming I'm working on a Flask app at app.py with dependencies in requirements.txt , a working flow would look roughly like this: # I am "robin" and I am in the docker group $ whoami robin $ groups robin docker # Install dependencies into a docker volume $ docker run -ti -v `pwd`:`pwd` -w `pwd` -v pydeps:/usr/local python:3-slim pip install -r requirements.txt Collecting Flask==0.12.2

Running as a host user within a Docker container

只谈情不闲聊 提交于 2021-02-17 15:12:58
问题 In my team we use Docker containers to locally run our website applications while we do development on them. Assuming I'm working on a Flask app at app.py with dependencies in requirements.txt , a working flow would look roughly like this: # I am "robin" and I am in the docker group $ whoami robin $ groups robin docker # Install dependencies into a docker volume $ docker run -ti -v `pwd`:`pwd` -w `pwd` -v pydeps:/usr/local python:3-slim pip install -r requirements.txt Collecting Flask==0.12.2