Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An example of a large scale Flask application using blueprints and extensions.

License

NotificationsYou must be signed in to change notification settings

cburmeister/flask-bones

Repository files navigation

flasks

flask-bones

An example of a large scale Flask application using blueprints and extensions.

Build Status

Setup

Quickly run the project usingdocker anddocker-compose:

docker-compose up -d

Create the database and seed it with some data:

docker-compose run --rm app flask create-dbdocker-compose run --rm app flask populate-db --num_users 5

Download front-end dependencies withyarn:

yarn install --modules-folder ./app/static/node_modules

Configuration

The following environment variables areoptional:

NamePurpose
APP_NAMEThe name of the application. i.e Flask Bones
MAIL_PORTThe port number of an SMTP server.
MAIL_SERVERThe hostname of an SMTP server.
MEMCACHED_HOSTThe hostname of a memcached server.
MEMCACHED_PORTThe port number of a memcached server.
POSTGRES_HOSTThe hostname of a postgres database server.
POSTGRES_PASSThe password of a postgres database user.
POSTGRES_PORTThe port number of a postgres database server.
POSTGRES_USERThe name of a postgres database user.
REDIS_HOSTThe hostname of a redis database server.
REDIS_PORTThe port number of a redis database server.
SECRET_KEYA secret key required to provide authentication.
SERVER_NAMEThe hostname and port number of the server.

Features

Caching with Memcached

fromapp.extensionsimportcache# Cache somethingcache.set('some_key','some_value')# Fetch it latercache.get('some_key')

Email delivery

fromapp.extensionsimportmailfromflask_mailimportMessage# Build an emailmsg=Message('User Registration',sender='admin@flask-bones.com',recipients=[user.email])msg.body=render_template('mail/registration.mail',user=user,token=token)# Sendmail.send(msg)

Asynchronous job scheduling with RQ

RQ is asimple job queue for python backed byredis.

Define a job:

@rq.jobdefsend_email(msg):mail.send(msg)

Start a worker:

flask rq worker

Queue the job for processing:

send_email.queue(msg)

Monitor the status of the queue:

flask rq info --interval 3

For help on all available commands:

flask rq --help

Stupid simple user management

fromapp.extensionsimportlogin_user,logout_user,login_required# Login userlogin_user(user)# You now have a global proxy for the usercurrent_user.is_authenticated# Secure endpoints with a decorator@login_required# Log out userlogout_user()

Password security that can keep up with Moores Law

fromapp.extensionsimportbcrypt# Hash passwordpw_hash=bcrypt.generate_password_hash('password')# Validate passwordbcrypt.check_password_hash(pw_hash,'password')

Easily swap between multiple application configurations

fromapp.configimportdev_config,test_configapp=Flask(__name__)classdev_config():DEBUG=Trueclasstest_config():TESTING=True# Configure for testingapp.config.from_object(test_config)# Configure for developmentapp.config.from_object(dev_config)

Form validation & CSRF protection with WTForms

Place a csrf token on a form:

{{ form.csrf_token }}

Validate it:

form.validate_on_submit()

Rate-limit routes

fromapp.extensionsimportlimiter@limiter.limit("5 per minute")@auth.route('/login',methods=['GET','POST'])deflogin():# ...return'your_login_page_contents'

Automated tests

Run the test suite:

pytest

Use any relational database using the SQLAlchemy ORM

fromapp.user.modelsimportUser# Fetch user by iduser=User.get_by_id(id)# Save current state of useruser.update()# Fetch a paginated set of usersusers=User.query.paginate(page,50)

Front-end asset management

Download front-end dependencies withyarn:

yarn install --modules-folder ./app/static/node_modules

Merge and compress them together withFlask-Assets:

flask assets build

Version your database schema

Display the current revision:

flask db current

Create a new migration:

flask db revision

Upgrade the database to a later version:

flask db upgrade

Internationalize the application for other languages (i18n)

Extract strings from source and compile a catalog (.pot):

pybabel extract -F babel.cfg -o i18n/messages.pot.

Create a new resource (.po) for German translators:

pybabel init -i i18n/messages.pot -d i18n -l de

Compile translations (.mo):

pybabel compile -d i18n

Merge changes into resource files:

pybabel update -i i18n/messages.pot -d i18n

About

An example of a large scale Flask application using blueprints and extensions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp