Flask

Flask migration fails

老子叫甜甜 提交于 2020-12-06 07:10:42
问题 I'm making migrations in Flask using unsurprisingly Flask-Migrate . once I execute python manage.py db init it creates directory migrations with initial migrations file. Then I execute python manage.py db migrate and I get this: ... ... target_metadata = current_app.extensions['migrate'].db.metadata AttributeError: 'NoneType' object has no attribute 'metadata' I understand from this output that 'migrate' is None hence I'm getting an attribute error. models.py: from sqlalchemy.sql import func

Flask migration fails

自作多情 提交于 2020-12-06 07:09:21
问题 I'm making migrations in Flask using unsurprisingly Flask-Migrate . once I execute python manage.py db init it creates directory migrations with initial migrations file. Then I execute python manage.py db migrate and I get this: ... ... target_metadata = current_app.extensions['migrate'].db.metadata AttributeError: 'NoneType' object has no attribute 'metadata' I understand from this output that 'migrate' is None hence I'm getting an attribute error. models.py: from sqlalchemy.sql import func

Flask Upload Image to S3 without saving it to local file system

北慕城南 提交于 2020-12-06 07:04:39
问题 I need to upload a a user submitted photo to an s3 bucket. However I keep getting the following error: TypeError: expected str, bytes or os.PathLike object, not FileStorage How am I able to store the file as string/bytes instead of FileStorage? The relevent code is as follows: @user_api.route('upload-profile-photo', methods=['PUT']) @Auth.auth_required def upload_profile_photo(): """ Upload User Profile Photo """ key = Auth.auth_user() bucket = 'profile-photos' content_type = request.mimetype

SQLAlchemy和Flask-SQLAlchemy的使用

你离开我真会死。 提交于 2020-12-06 04:09:26
1. SQLAlchemy ORM框架、通用 Django-Model:基于django 1. 安装 pip install sqlalchemy 2. 使用 1. 约束 primary_key auto_increment nullable index unique 2. 数据类型 INT、INTEGER、Integer:都是整型 CHAR、 NCHAR、VARCHAR、 NVARCHAR、String:都是字符串 # 声明一个基类 from sqlalchemy.ext.declarative import declarative_base BaseModel = declarative_base() from sqlalchemy import Column, INT, String # ORM:object relationship mapping class User(BaseModel): # 创建一个table __tablename__ = 'user' id = Column(INT, primary_key=True, auto_increment=True) name = Column(String(32), nullable=False, index=True, unique=True) # 数据库引擎创建 from sqlalchemy.engine

Android客户端与Python服务器端通信之上传图片

谁都会走 提交于 2020-12-05 10:58:03
继上篇成功的与服务器端通信上之后,我现在需要将安卓本地的图片上传到服务端。服务端接收图片存下来。 参考: https://blog.csdn.net/qq_26906345/article/details/91045074 Android客户端: 点击按钮会将文件上传到服务器,图片的地址我暂时是写死的。 服务器端: 接收到图片存储到写好的位置 相关代码如下: Android客户端:由于布局文件只有一个按钮,故不在此展出。 MainActivity.java: 主要就是设置了对按钮的监听。 package com.example.vesper.uploadpic; import android.os.Environment; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.io.File; public class MainActivity extends AppCompatActivity { private Button button; @Override protected void onCreate(Bundle

python基础面试题整理---从零开始 每天十题(01)

北城以北 提交于 2020-12-04 23:58:21
  最近在弄flask的东西,好久没写博客的,感觉少了点什么,感觉被别人落下好多,可能渐渐的养成了写博客的习惯吧。也是自己想学的东西太多了(说白了就是基础太差了,只是know how,不能做到konw why)。   不说那些毒鸡汤了,我们来说说我们今天的python基础面试题吧。 一, Q:python的优缺点有什么?   A:优点:     1,基础语法简单易学,对于初学者来说,语法还是相对简单的,比较容易学习,网上的学习资料也很多。     2,面向对象,在python里继承和封装较多,而python的多态还是相对较少的(起个不一样的名字不就可以吗....对java的多态表示无奈),从而减少了大量代码的输出。     3,语言简洁,相对java比,语法要比java简单很多(我只会java和python,会一点点Node.js和前端的VUE)     4,开源,python语言开源便于我们自行去维护和更深入的了解源码。     5,丰富的社区资源,具有超级丰富的三方库。     缺点:     1,运行速度慢,由于python是解释性语言,对比其它语言要相对慢一些。     2,python2和python3不兼容(python2在2020年1月就不在维护)     3,代码安全性较弱,我们发布项目,其实就是发布我们的源码,安全性差。   MA

Pylint false positive for Flask's “app.logger”: E1101: Method 'logger' has no 'debug' member (no-member)

妖精的绣舞 提交于 2020-12-04 20:00:24
问题 Using flask's app.logger member functions (such as app.logger.error ) causes pylint to report E1101 ( no-member ) errors, even though these members of app.logger are defined at runtime. This can be reproduced by using the following files: app.py import flask app = flask.Flask(__name__) @app.route('/') def say_hello(): app.logger.debug('A debug message') app.logger.error('An error message') return 'hello' requirements.txt pylint==2.1.0 Flask==1.0.2 Sample commands for reproducing the issue,

Pylint false positive for Flask's “app.logger”: E1101: Method 'logger' has no 'debug' member (no-member)

邮差的信 提交于 2020-12-04 19:52:18
问题 Using flask's app.logger member functions (such as app.logger.error ) causes pylint to report E1101 ( no-member ) errors, even though these members of app.logger are defined at runtime. This can be reproduced by using the following files: app.py import flask app = flask.Flask(__name__) @app.route('/') def say_hello(): app.logger.debug('A debug message') app.logger.error('An error message') return 'hello' requirements.txt pylint==2.1.0 Flask==1.0.2 Sample commands for reproducing the issue,

Python 爬虫之Scrapy《上》

霸气de小男生 提交于 2020-12-04 07:30:31
1 什么是Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 2 工作流程是怎么样的 下图是从网络上找的一张Scrapy的工作流程图,并且标注了相应的中文说明信息: 3 Scrapy框架的六大组件 它们分别是: 调度器(Scheduler) 下载器(Downloader) 爬虫(Spider) 中间件(Middleware) 实体管道(Item Pipeline) Scrapy引擎(Scrapy Engine) 4 工作流程如下 Step1 . 当爬虫(Spider)要爬取某URL地址的页面时,使用该URL初始化Request对象提交给引擎(Scrapy Engine),并设置回调函数,Spider中初始的Request是通过调用start_requests() 来获取的。start_requests() 读取start_urls 中的URL,并以parse为回调函数生成Request 。 备注:你所创建的项目名.py 文件里面有一个列表:start_urls=[‘http://lab.scrapyd.cn/page/1/‘] (这是我的示例),这里的start_requests() 读取的start_urls 就是来自于这里,这个文件在大家创建爬虫项目时会自动新建。parse(

Atomic log file rotation with Flask and RotatingFileHandler

半腔热情 提交于 2020-12-04 03:58:54
问题 I use standard RotatingFileHandler within my Flask application with next parameters: maxBytes=10 * 1024 * 1024, backupCount=50 . App is managed by uWSGI behind nginx. uWSGI config file part looks like this: processes = 16 enable-threads = true threads = 10 Right after start of an app everything (I mean logging) works well. But after first log file rotation some processes (and maybe threads too) continue writing to rotated file and some - to new one. It is obvious. But for me it is not so