Giter Club home page Giter Club logo

flask-boost's Introduction

Flask-Boost

Latest Version Downloads Per Month Python Versions The MIT License

Flask application generator for boosting your development.

Features

  • Well Defined Project Structure
    • Use factory pattern to generate Flask app.
    • Use Blueprints to organize controllers.
    • Split controllers, models, forms, utilities, assets, Jinja2 pages, Jinja2 macros into different directories.
    • Organize Jinja2 page assets (HTML, JavaScript, CSS) to the same directory.
    • Organize Jinja2 macro assets (HTML, JavaScript, CSS) to the same directory.
  • Batteries Included
    • Use Flask-SQLAlchemy and Flask-Migrate as database tools.
    • Use Flask-WTF to validate forms.
    • Use Flask-Script to help writing scripts.
    • Use permission to define permissions.
    • Use Bootstrap as frontend framework.
    • Use Bower to manage frontend packages.
    • Use Gulp and FIS to compile static assets.
    • Use Gunicorn to run Flask app and Supervisor to manage Gunicorn processes.
    • Use Fabric as deployment tool.
    • Use Sentry to log exceptions.
    • Use Nginx to serve static files.
  • Scaffold Commands
    • Generate project files: boost new <project>
    • Generate controller files: boost new controller <controller>
    • Generate action files: boost new action <controller> <action> [-t]
    • Generate form files: boost new form <form>
    • Generate model files: boost new model <model>
    • Generate macro files: boost new macro <category> <macro> or boost new macro <macro>

Installation

pip install flask-boost

Development Guide

Init project

boost new <your_project_name>

Setup backend requirements

cd <your_project_dir>
virtualenv venv
. venv/bin/activate (venv\Scripts\activate in Windows)
pip install -r requirements.txt

Note: if you failed in pip install -r requirements.txt in Windows, try to install package binaries directly:

Init database

Create database with name your_project_name and encoding utf8.

Update SQLALCHEMY_DATABASE_URI in config/development.py as needed.

Then init tables:

python manage.py db upgrade

Run app

Run local server:

python manage.py run

Setup frontend requirements

Install Node.js first and then install Bower, FIS and Gulp globally:

npm install -g bower
npm install -g fis
npm install -g fis-postpackager-simple
npm install -g gulp

Install local packages:

npm install
bower install

Run Gulp watch task

gulp watch

LiveReload support

Install LiveReload browser extension from here.

And use python manage.py live instead of python manage.py run to start app.

Scaffold commands

boost new <project>
boost new controller <controller>
boost new action <controller> <action> [-t]
boost new form <form>
boost new model <model>
boost new macro <category> <macro>
boost new macro <macro>
boost -v
boost -h

Recommended IDE

PyCharm is the recommended IDE for Flask-Boost.

Recommended preferences:

  • In Preferences -> Project -> Project Interpreter, set venv as project interpreter.
  • In Preferences -> Project -> Project Structure, set application/pages and application/macros as template folders, set application and application/static/css as resource folders.
  • In Language & Frameworks -> JavaScript -> Bower, set bower.json as bower.json.

Recommended PyCharm plugins:

  • .ignore
  • Markdown
  • Bootstrap3

First Production Deploy

Config server

Install mysql-server, python-virtualenv, git, supervisor, nginx, g++, python-dev, libmysqlclient-dev, libxml2-dev, libxslt-dev on your server.

Install requirements

git clone **.git
cd <your_project_dir>
virtualenv venv
. venv/bin/activate
pip install -r requirements.txt

Config app

Save config/production_sample.py as config/production.py, update configs in config/production.py as needed and transfer it to server.

Note: remember to update SECRET_KEY in config/production.py! You can generate random secret key as follows:

>>> import os
>>> os.urandom(24)

Init database

Create database with name your_project_name and encoding utf8.

And run:

export MODE=PRODUCTION
python manage.py db upgrade

Copy config files

Update project root path as needed in deploy/nginx.conf and deploy/supervisor.conf.

cp deploy/flask_env.sh /etc/profile.d/
cp deploy/nginx.conf /etc/nginx/conf.d/<your_project_name>.conf
cp deploy/supervisor.conf /etc/supervisor/conf.d/<your_project_name>.conf

Build assets

Install Node.js first and then install Bower, FIS and Gulp globally:

npm install -g bower
npm install -g fis
npm install -g fis-postpackager-simple
npm install -g gulp

Install local packages:

npm install
bower install

Then:

gulp
python manage.py build

Start app

service nginx restart
service supervisor restart

Daily Production Deploy

Update HOST_STRING in config with the format user@ip.

Commit your codes and run:

git push && fab deploy

P.S. If you wanna to deploy flask with Apache2, see this post.

License

MIT

flask-boost's People

Contributors

daimon99 avatar hustlzp avatar royopa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-boost's Issues

TypeError: 'encoding' is an invalid keyword

After I run the command boost new boost-test, I got this error:

Start generating project files.
New: ~/workspace/python/boost-test/
New: ~/workspace/python/boost-test/.gitignore
Traceback (most recent call last):
  File "/usr/local/bin/boost", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/flask_boost/cli.py", line 297, in main
    generate_project(args)
  File "/usr/local/lib/python2.7/site-packages/flask_boost/cli.py", line 87, in generate_project
    _rewrite_and_copy(src_file, dst_file, project_name)
  File "/usr/local/lib/python2.7/site-packages/flask_boost/cli.py", line 320, in _rewrite_and_copy
    with open(abs_path, 'w', encoding='utf-8') as new_file:
TypeError: 'encoding' is an invalid keyword argument for this function

Error using Python3 - python3 manage.py db upgrade - except ImportError, e:

(venv)rodrigo@rodrigo-xubuntu:/projects/flask_boost_site$ python3 manage.py db upgrade
Traceback (most recent call last):
File "manage.py", line 4, in
from application import create_app
File "/home/rodrigo/projects/flask_boost_site/application/init.py", line 19, in
from config import load_config
File "/home/rodrigo/projects/flask_boost_site/config/init.py", line 18
except ImportError, e:
^
SyntaxError: invalid syntax
(venv)rodrigo@rodrigo-xubuntu:
/projects/flask_boost_site$

Question:How to generate table with SQLAlchemy?

I noticed the database object file in ‘/home/yileye/project/monitor/application/models‘

And after I run the command ’boost new model‘ ,I can see the new model file in this path

But how I use this file to generate the table in mysql?

defautl admin user in user table

after:

  my_boost$ python manage.py db upgrade

I get user table but with no user, so no way to login:

mysql root@localhost:my_boost> select * from `user`;
+------+--------+---------+----------+------------+------------+--------------+
| id   | name   | email   | avatar   | password   | is_admin   | created_at   |
|------+--------+---------+----------+------------+------------+--------------|
+------+--------+---------+----------+------------+------------+--------------+
0 rows in set
Time: 0.003s 
mysql root@localhost:my_boost> 

Should I create it myself ?

Does it can work?

env: windows/python2.7
error1: when install, exception throwed: tmpfile move exception. then I modify the source code, hard cord the args with "new project balabala"
error2:
from application import create_app
from application.models import db
no application found.
...

SQLAlchemy table autoloading

Hi Zhipeng, thanks for this awesome package.

I'm used to design my own database tables, relationships and primary keys, and then use SQLAlchemy autoloading function to create table models. The database is shared among other applications, so I like to do migrations manually, without using Flask-Migration and Alembic.

This is a example model (before using Flask-Boost), accounts.py

from app import app, db
main_engine = db.get_engine(app, bind=None)

class Accounts(db.Model):
__tablename__ = 'accounts'
__table_args__ = {'autoload':True, 'autoload_with':main_engine}

Now that I'm using Flask-Boost, first I type boost new model accounts to generate the model, and then use tools like sqlacodegen to complete the model's definition. Each time I update my database schema, I need to regenerate my models.

Is there a way to use SQLAlchemy autoloading feature with Flask-Boost?

Thanks in advance.

It's possible to generate sub-actions?

For example, I generate an API controller with boost new controller api then I tried to generate the action users/me with boost new action api users/me. The code generated was

@bp.route('/api/users/me')
def users/me():
    pass

clearly wrong. So, my question is, how to generate this kind of action? In case of an API I should use another approach, like generate other controllers and somehow put them together?

PS: I know that I can just change def users/me() to def users_me() but I'm asking about the right approach for this...

在SAE环境中,static文件夹路径似乎有问题。

本地环境中一切正常。
但在sae中,因为要引入第三方库,在sae中需要在wsgi最前面加入下面这一段
root = os.path.dirname(file)
sys.path.insert(0, os.path.join(root, 'site-packages'))
然后template中的模板里的static函数就用不了了,打开网页下方提示静态资源404

Error using Python3 - UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 594: invalid continuation byte

I have the error below with Python3.4

rodrigo@rodrigo-xubuntu:~/projects$ boost new your_project_name
Start generating project files.
Traceback (most recent call last):
File "/usr/local/bin/boost", line 9, in
load_entry_point('Flask-Boost==0.4.4', 'console_scripts', 'boost')()
File "/usr/local/lib/python3.4/dist-packages/flask_boost/cli.py", line 80, in main
execute(args)
File "/usr/local/lib/python3.4/dist-packages/flask_boost/cli.py", line 69, in execute
_rewrite_and_copy(src_file, dst_file, project_name)
File "/usr/local/lib/python3.4/dist-packages/flask_boost/cli.py", line 102, in _rewrite_and_copy
for line in old_file:
File "/usr/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdc in position 594: invalid continuation byte

Compatible with Python 3.x

Some decoding and encoding code is not compatible with python 3.x

I think I will contribute some code to fix it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.