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

flask-base

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

flask-base

A Flask application template with the boilerplate code already done for you.

Documentation available at http://hack4impact.github.io/flask-base.

What's included?

  • Blueprints
  • User and permissions management
  • Flask-SQLAlchemy for databases
  • Flask-WTF for forms
  • Flask-Assets for asset management and SCSS compilation
  • Flask-Mail for sending emails
  • gzip compression
  • Redis Queue for handling asynchronous tasks
  • ZXCVBN password strength checker
  • CKEditor for editing pages

Demos

Home Page:

Registering User:

Admin Editing Page:

Admin Editing Users:

Setting up

Create your own repository from this Template

Navigate to the main project page and click the big, green "Use this template" button at the top right of the page. Give your new repository a name and save it.

Clone the repository
$ git clone https://github.com/YOUR_USERNAME/REPO_NAME.git
$ cd REPO_NAME
Initialize a virtual environment

Windows:

$ python3 -m venv venv
$ venv\Scripts\activate.bat

Unix/MacOS:

$ python3 -m venv venv
$ source venv/bin/activate

Learn more in the documentation.

Note: if you are using a python before 3.3, it doesn't come with venv. Install virtualenv with pip instead.

(If you're on a Mac) Make sure xcode tools are installed
$ xcode-select --install
Add Environment Variables

Create a file called config.env that contains environment variables. Very important: do not include the config.env file in any commits. This should remain private. You will manually maintain this file locally, and keep it in sync on your host.

Variables declared in file have the following format: ENVIRONMENT_VARIABLE=value. You may also wrap values in double quotes like ENVIRONMENT_VARIABLE="value with spaces".

  1. In order for Flask to run, there must be a SECRET_KEY variable declared. Generating one is simple with Python 3:

    $ python3 -c "import secrets; print(secrets.token_hex(16))"
    

    This will give you a 32-character string. Copy this string and add it to your config.env:

    SECRET_KEY=Generated_Random_String
    
  2. The mailing environment variables can be set as the following.We recommend using Sendgrid for a mailing SMTP server, but anything else will work as well.

    MAIL_USERNAME=SendgridUsername
    MAIL_PASSWORD=SendgridPassword
    

Other useful variables include:

Variable Default Discussion
ADMIN_EMAIL flask-base-admin@example.com email for your first admin account
ADMIN_PASSWORD password password for your first admin account
DATABASE_URL data-dev.sqlite Database URL. Can be Postgres, sqlite, etc.
REDISTOGO_URL http://localhost:6379 Redis To Go URL or any redis server url
RAYGUN_APIKEY None API key for Raygun, a crash and performance monitoring service
FLASK_CONFIG default can be development, production, default, heroku, unix, or testing. Most of the time you will use development or production.
Install the dependencies
$ pip install -r requirements.txt
Other dependencies for running locally

You need Redis, and Sass. Chances are, these commands will work:

Sass:

$ gem install sass

Redis:

Mac (using homebrew):

$ brew install redis

Linux:

$ sudo apt-get install redis-server

You will also need to install PostgresQL

Mac (using homebrew):

brew install postgresql

Linux (based on this issue):

sudo apt-get install libpq-dev
Create the database
$ python manage.py recreate_db
Other setup (e.g. creating roles in database)
$ python manage.py setup_dev

Note that this will create an admin user with email and password specified by the ADMIN_EMAIL and ADMIN_PASSWORD config variables. If not specified, they are both flask-base-admin@example.com and password respectively.

[Optional] Add fake data to the database
$ python manage.py add_fake_data

Running the app

$ source env/bin/activate
$ honcho start -e config.env -f Local

For Windows users having issues with binding to a redis port locally, refer to this issue.

Gettin up and running with Docker and docker-compose:

Clone the repository
$ git clone https://github.com/YOUR_USERNAME/REPO_NAME.git
$ cd REPO_NAME
Create and run the images:
$ docker-compose up
Create database and initial data for development:
$ docker-compose exec server ./init_database.sh

It will deploy 5 docker images:

  • server: Flask app running in http://localhost:5000.
  • worker: Worker ready to get tasks.
  • postgres: Postgres SQL isolated from the app.
  • adminer: Web client for database management, running in http://localhost:8080.
  • redis: Redis SQL isolated from the app

Formatting code

Before you submit changes to flask-base, you may want to autoformat your code with python manage.py format.

Contributing

Contributions are welcome! Please refer to our Code of Conduct for more information.

Documentation Changes

To make changes to the documentation refer to the Mkdocs documentation for setup.

To create a new documentation page, add a file to the docs/ directory and edit mkdocs.yml to reference the file.

When the new files are merged into master and pushed to github. Run mkdocs gh-deploy to update the online documentation.

Related

https://medium.freecodecamp.com/how-we-got-a-2-year-old-repo-trending-on-github-in-just-48-hours-12151039d78b#.se9jwnfk5

License

MIT License

 相关资料
  • 问题内容: 在官方的快速入门中,建议在使用单个 模块 时使用: 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