当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

flask-empty

授权协议 Readme
开发语言 Python
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 吕向荣
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Flask Empty

version 0.6.3

Flask-Empty is a simple flask boilerplate for fast prototyping. Justuse cookiecutter and create a new project in no time.

# if cookiecutter is not installed
pip3 install cookiecutter

# using cookiecutter // linux/Mac
cookiecutter https://github.com/italomaia/flask-empty

# answer the prompt and you're done!

Getting Started

You're advised to use venv from here on.In your project folder, create and enable it like this:

python3 -m venv venv
. venv/bin/activate  # [.csh|.fish]

# install required packages
pip3 install -r requirements.txt

# loads env variables and runs the project in development mode
make run-dev

Getting Started With Docker

Given you have up-to-date docker installed in your machine,all you need to do is:

# build container image
docker build . -t my-project-name
# run container in development mode
docker run --rm -p 5000:5000 my-project-name

Environment Variables

For flask to run correctly, some environment variables need to be set. The ones needed by your project can be seen in the Dockerfile or Makefile files.For a list of all other optional environment variables, check this link. When using docker, you can easely set them inline before each run. When using docker-compose, set them in the yaml configuration file for each environment.

Important files to be aware of

/extensions.py all extension instances that need initialization should be availablehere, so Empty can see and initialize them for you. If instantiated somewhere else, just import them here and you should be fine.

/config.py has pre-set configuration classes for you to meddle with. They're are all self explanatory and commented.

/main.py instantiates your project's main class. Override it to quickly add custom extension setups, simple views, context processors, etc. It already has some sensitive defaults for most use cases. See https://github.com/italomaia/empty for the available options.

<project>/<project>.ini is the configuration file used withuwsgi. Use it like this:

uwsgi --ini your_project.ini

commands.py adds few very useful commandline commands (...) to help your development productivity. You can also add your own. Check available commands by running FLASK_ENV=development FLASK_CONFIG_DEFAULT=Dev flask in the terminal.

Heroku

Empty comes with a pre-configured procfile and heroku() wrapper for app_factory. No setup required.

Other topics

Templates

There are some error templates bundled with flask-empty by default. All empty right now. Just fill them up for your project.

Macros

You can use the jinja2 macros available in templates/macros to easily integrate your jinja2 templates with flask extensions like wtforms and common tasks like showing flash messages.

Available macros, formhelpers and flashing are very useful.

Blueprints

You can create blueprints easily with make new-app. The will live, by defaultat apps folder. Remember to configure your blueprints in config.py so that theycan be properly loaded.

Json Friendly

Variables true, false and null are now supported as aliases for True, False and None.This way, valid json can be copy-pasted directly into your code and will be interpretedas valid python. Ex: data = {"x": true, "y": false, "z": null}

Supported Extensions

Flask-SQLAlchemy

While creating your project, Flask-Empty will ask you if you wish to enable SQL support. Confirm if you do so and Flask-SQLAlchemy will be made available. See config.py for its default configuration.

_ps: currently, db-create will only create your models if they are imported somewhere in your application.

By somewhere, try the same module where your Blueprint instance is defined.

Flask-Mongoengine

As mongodb is really cool, supporting it is a must. Just say yes at the prompt when askedand Flask-Mongoengine will be setup for you.

Flask-WTF

Flask-WTF is the "the facto" extension for handling forms with Flask. It is simply great, and Flask-Emptysupports it! Just say "yes" during project creation and Flask-WTF support will be on.

Flask-Admin

Just create an admin.py file in your blueprint, define your admin models inside and changeLOAD_MODULES_EXTENSIONS to also pre-load admin, like this:

Flask-Marshmallow

Gives you, almost for free, model serialization, deserialization and validation. Alsoquite handy for fast development of rest applications.

Flask-Security

Get user session and permissioning out-of-the-box with this great project.

Examples

The blog example in this project is probably outdated by now, so, just create a new projectand mess around to your heart's content for quick learning.

FAQ

Is flask-empty boilerplate compatible with flask 0.x? Cuz' that's what my app uses.

Right now, flask-empty is a very simple project where many good practices and code examples were glued together.

Until recently I was focused in keeping backward compatibility with flask 0.8. Well, that goal is no more.

Flask-empty will be compatible with the latest version of Flask and, by chance, with previous versions. Things will be easier (for me!) this way.

So, which is the oldest version where flask-empty works?

In my last test, version 1.0.

I think flask-empty should have this and that configured by default. Will you add support?

My current goals are:

  • Make flask-empty real easy to start a project with
  • Keep things simple and robust

If your suggestion is simple, VERY useful and has little overhead, I'll probably consider adding it to the project.

If you make the code and send a pull request, then I'll consider it real hard. Now, if your suggestion is rejected or advised in a different approach, don't get sad (you're awesome ;).

I just made a cool example with flask-empty and want to add it to examples.

Pull request it for evaluation ;)Just keep in mind that good examples are short (not really...) and focused in it's showcase.

  • 在认识Flask-SQLAlchemy之前,先要了解ORM和SQLAlchemy。   ORM: 概念 ORM:对象关系映射,英语:(Object Relational Mapping,简称ORM,或O/RM,或O/R mapping) 产生背景: 面向对象是从软件工程基本原则(如耦合、聚合、封装)的基础上发展起来的,而关系型数据库则是从数学理论发展而来的,两套理论存在显著的区别。为了解决这个不匹

  • 入门 初始化 第一步是为Flask应用初始化一个空的管理界面: from flask import Flask from flask_admin import Admin app = Flask(__name__) admin = Admin(app, name='microblog', template_mode='bootstrap3') # Add administrative views

  • 1 程序启动阶段 from flask import Flask app = Flask(__name__) @app.route('/') def index(): return 'hello flask' if __name__ == '__main__': app.run() 2 请求到来 1.app.__call__ 2.app.wsgi_app 3.ctx.pus

  • Flask-Migrate Flask-Migrate是一个扩展,使用Alembic处理Flask应用程序的SQLAlchemy数据库迁移。数据库操作通过Flask命令行界面或Flask-Script扩展提供。 问题思考: ​ 我们已经有了db.create_all()和db.drop_all(),我们为什么要用flask-migrate呢? 安装 ​ pip install flask-migr

  • 1、安装 pip install Flask-Migrate 2、创建对象 1、创建一个sql_.py文件 from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_script import Manager from flask_migrate import Migrate,MigrateCommand

  • 简介 通过命令行执行数据库操作 因为使用db.create_all()进行ORM映射时模型修改后需要删除原来的表才能重新映射新模型,所以使用flas-migrate来进行数据库迁移,通过命令行对被修改的模型进行新的映射 安装Flask-Migrate 进入虚拟环境并执行activate 执行pip install flask-migrate (flask-env) C:\pyenv\flask-e

 相关资料
  • 问题内容: 在官方的快速入门中,建议在使用单个 模块 时使用: 2. …如果您使用的是单个模块(如本例所示),则应使用,因为取决于它是作为应用程序启动还是作为模块导入,其名称将有所不同(与实际导入名称不同)。… 但是,在他们的API文档中,当我的应用程序为 软件包 时,建议进行硬编码: 因此,您在此处提供的内容很重要。如果使用单个模块,则始终为正确的值。但是,如果您使用的是包,通常建议在其中硬编码

  • 在前面,我们介绍了 REST Web 服务,并使用 Flask 提供服务。这里,我们使用第三方库 Flask-RESTful,它使得在 Flask 中提供 REST 服务变得更加简单。 安装 使用 pip 安装: $ pip install flask-restful 使用 下面我们主要使用官方文档的例子进行说明。 Hello World 我们先来看一个简单的例子。 # -*- coding: u

  • Bootstrap 是 Twitter 开源的一个 CSS/HTML 框架,它让 Web 开发变得更加迅速,简单。要想在我们的 Flask 应用中使用 Boostrap,有两种方案可供选择: 第 1 种,在我们的 Jinja 模板中直接引入 Bootstrap 层叠样式表 (CSS) 和 JavaScript 文件,比如 bootstrap.min.css,bootstrap.min.js; 第

  • 在 Web 应用中,我们经常需要保护我们的 api,以避免非法访问。比如,只允许登录成功的用户发表评论等。Flask-HTTPAuth 扩展可以很好地对 HTTP 的请求进行认证,不依赖于 Cookie 和 Session。本文主要介绍两种认证的方式:基于密码和基于令牌 (token)。 安装 使用 pip 安装: $ pip install Flask-HTTPAuth 基于密码的认证 为了简化

  • 假设你的 Web 服务对于某些请求比较耗时,而该请求的返回结果在较短的时间内(比如 5 分钟内)都是足够有效的,这时你能想到什么方法去改善这种状况呢?缓存?对,至少这是一种提高性能的最简单的方法。 Flask 本身不提供缓存功能,但是作为 Flask 核心的 Werkzeug 框架则提供了一个简单的缓存对象 SimpleCache,它将缓存项存放在 Python 解释器的内存中。使用 Simple

  • MongoDB 是一个文档型数据库,是 NoSQL (not only SQL) 的一种,具有灵活、易扩展等诸多优点,受到许多开发者的青睐。MongoEngine 是一个用来操作 MongoDB 的 ORM 框架,如果你不知道什么是 ORM,可以参考 Flask-SQLAlchemy 一节。在 Flask 中,我们可以直接使用 MongoEngine,也可使用 Flask-MongoEngine