diff --git a/README.md b/README.md index 7e88f91..bbe1710 100644 --- a/README.md +++ b/README.md @@ -14,10 +14,29 @@ mana ## 使用mana: ### 1. mana init --> 构建你的项目 +#### 1. 构建一般项目(无蓝图、无数据库、无配置文件) - ~> mana init my_project + $ mana init my_project -你已经创建了你的目录结构(如图)
+创建的目录结构(如图)
+ + |-app/ ---- __init__.py + |-test/ + my_project - | views.py + |-requirement.txt forms.py + |-README.md templates + | static + +文件中预填代码
+[app/__init__.py预填代码](https://github.com/neo1218/mana/blob/master/examples/GoodIdea/app/__init__.py) : 创建了flask app, 导入了基本配置
+现在你只需开开兴兴的写视图了 + +#### 2. 构建中型项目(无蓝图、有数据库、有配置文件) + + 默认集成的是flask-sqlalchemy数据库扩展🍺 + $ mana init my_project --sql=true + +创建的目录结构(如图)
|-app/ ---- __init__.py |-test/ models.py @@ -26,9 +45,25 @@ mana |-README.md templates | static -并且在相关文件中预填了代码
-[config.py预填代码](https://github.com/neo1218/mana/blob/master/examples/GoodIdea/config.py) : 三个配置类, 对应生产、测试、开发环境配置
+文件中预填代码
[app/__init__.py预填代码](https://github.com/neo1218/mana/blob/master/examples/GoodIdea/app/__init__.py) : 创建了flask app, 导入了基本配置 +[config.py预填代码](): 测试、生产、开发环境下配置 +[models.py预填代码](): 导入 db 对象 + +#### 3. 构建大型项目(有蓝图、有数据库、有配置文件) + + 将mana init与mana blue搭配使用 + +命令如下 + + # 构建项目 + $ mana init my_project --sql=true + + # 自动创建、注册蓝图 + $ mana blue my_project <蓝图名> + +具体见 ~mana blue~ 的用法 + ### 2. mana install (--venv) --> 安装flask扩展 在 requirement.txt 中写入你希望安装的扩展的名称
@@ -50,17 +85,7 @@ ex: 这样你的扩展就会被安装到全局中
不过强烈建议使用使用虚拟环境进行开发,参见[virtualenv](http://docs.jinkan.org/docs/flask/installation.html#virtualenv)
- -### 3. mana sql --> 集成 flask-sqlalchemy 处理关系型数据库 -对于sql数据库的处理, flask-sqlalchemy 是我最常用的扩展,使用mana可以快速集成flask-sqlalchemy并初始化扩展 - - 进入与项目根目录同级的目录 🍺 - $ mana sql project_name - -接下来,你只需要专心于models.py的数据库类设计与编码了
- - -### 4. mana manage --> 使用 manage.py 管理你的项目 +### 3. mana manage --> 使用 manage.py 管理你的项目 还可以使用mana创建manage.py集成flask-script和flask-migrate管理我们的项目 进入与项目根目录同级的目录 🍺 @@ -99,7 +124,7 @@ ex: >> User -### 5. mana blue (--prefix)--> 自动注册蓝图 +### 4. mana blue (--prefix)--> 自动注册蓝图 进入与项目根目录同级的目录 🍺 $ mana blue project_name bluep @@ -111,14 +136,14 @@ ex: 这样就可以通过 /bluep/... 去访问蓝图对应的视图 -### 6. mana deploy --> deploy flask application on wsgi server +### 5. mana deploy --> deploy flask application on wsgi server 进入与项目根目录同级的目录 🍺 $ mana deploy project_name --host=121.43.230.104 --port=2333 这样就可以创建wsgi.py去部署你的flask应用 -### 7. mana what? --> use your imagination .. +### 6. mana what? --> use your imagination .. 未完 .... 待续 .... diff --git a/examples/init_cfg_project/README.md b/example/Test/README.md similarity index 100% rename from examples/init_cfg_project/README.md rename to example/Test/README.md diff --git a/examples/init_project/app/__init__.py b/example/Test/app/__init__.py similarity index 100% rename from examples/init_project/app/__init__.py rename to example/Test/app/__init__.py diff --git a/examples/init_cfg_project/app/forms.py b/example/Test/app/forms.py similarity index 100% rename from examples/init_cfg_project/app/forms.py rename to example/Test/app/forms.py diff --git a/examples/init_cfg_project/app/views.py b/example/Test/app/views.py similarity index 100% rename from examples/init_cfg_project/app/views.py rename to example/Test/app/views.py diff --git a/examples/init_cfg_project/requirement.txt b/example/Test/requirement.txt similarity index 100% rename from examples/init_cfg_project/requirement.txt rename to example/Test/requirement.txt diff --git a/examples/init_project/README.md b/example/Test2/README.md similarity index 100% rename from examples/init_project/README.md rename to example/Test2/README.md diff --git a/examples/init_sql_config/app/__init__.py b/example/Test2/app/__init__.py similarity index 91% rename from examples/init_sql_config/app/__init__.py rename to example/Test2/app/__init__.py index bbdae36..4501dc4 100644 --- a/examples/init_sql_config/app/__init__.py +++ b/example/Test2/app/__init__.py @@ -21,3 +21,4 @@ from . import views, models, forms app.register_blueprint('share', url_prefix='/share') +app.register_blueprint('book') diff --git a/examples/init_sql_config/app/__init__.pyc b/example/Test2/app/__init__.pyc similarity index 62% rename from examples/init_sql_config/app/__init__.pyc rename to example/Test2/app/__init__.pyc index ce9471a..764cad0 100644 Binary files a/examples/init_sql_config/app/__init__.pyc and b/example/Test2/app/__init__.pyc differ diff --git a/example/Test2/app/book/__init__.py b/example/Test2/app/book/__init__.py new file mode 100644 index 0000000..531e7f8 --- /dev/null +++ b/example/Test2/app/book/__init__.py @@ -0,0 +1,13 @@ +# coding: utf-8 +""" + ~~~~~~~ + +""" + +from flask import Blueprint + + +book = Blueprint("book", __name__, static_folder='static', template_folder='templates') + + +from . import views, forms diff --git a/examples/init_project/app/forms.py b/example/Test2/app/book/forms.py similarity index 100% rename from examples/init_project/app/forms.py rename to example/Test2/app/book/forms.py diff --git a/examples/init_project/app/views.py b/example/Test2/app/book/views.py similarity index 100% rename from examples/init_project/app/views.py rename to example/Test2/app/book/views.py diff --git a/examples/init_sql_config/app/forms.py b/example/Test2/app/forms.py similarity index 100% rename from examples/init_sql_config/app/forms.py rename to example/Test2/app/forms.py diff --git a/example/Test2/app/forms.pyc b/example/Test2/app/forms.pyc new file mode 100644 index 0000000..bb71394 Binary files /dev/null and b/example/Test2/app/forms.pyc differ diff --git a/examples/init_sql_config/app/models.py b/example/Test2/app/models.py similarity index 79% rename from examples/init_sql_config/app/models.py rename to example/Test2/app/models.py index 8eedde3..9f66b15 100644 --- a/examples/init_sql_config/app/models.py +++ b/example/Test2/app/models.py @@ -7,3 +7,6 @@ """ from . import db + +class User(): + pass diff --git a/example/Test2/app/models.pyc b/example/Test2/app/models.pyc new file mode 100644 index 0000000..2b446cc Binary files /dev/null and b/example/Test2/app/models.pyc differ diff --git a/examples/init_sql_config/app/share/__init__.py b/example/Test2/app/share/__init__.py similarity index 100% rename from examples/init_sql_config/app/share/__init__.py rename to example/Test2/app/share/__init__.py diff --git a/examples/init_sql_config/app/share/forms.py b/example/Test2/app/share/forms.py similarity index 100% rename from examples/init_sql_config/app/share/forms.py rename to example/Test2/app/share/forms.py diff --git a/examples/init_sql_config/app/share/views.py b/example/Test2/app/share/views.py similarity index 100% rename from examples/init_sql_config/app/share/views.py rename to example/Test2/app/share/views.py diff --git a/examples/init_sql_config/app/views.py b/example/Test2/app/views.py similarity index 100% rename from examples/init_sql_config/app/views.py rename to example/Test2/app/views.py diff --git a/example/Test2/app/views.pyc b/example/Test2/app/views.pyc new file mode 100644 index 0000000..9122fa9 Binary files /dev/null and b/example/Test2/app/views.pyc differ diff --git a/examples/init_sql_config/config.py b/example/Test2/config.py similarity index 100% rename from examples/init_sql_config/config.py rename to example/Test2/config.py diff --git a/example/Test2/config.pyc b/example/Test2/config.pyc new file mode 100644 index 0000000..bf66141 Binary files /dev/null and b/example/Test2/config.pyc differ diff --git a/examples/init_sql_config/manage.py b/example/Test2/manage.py similarity index 100% rename from examples/init_sql_config/manage.py rename to example/Test2/manage.py diff --git a/example/Test2/requirement.txt b/example/Test2/requirement.txt new file mode 100644 index 0000000..521e32d --- /dev/null +++ b/example/Test2/requirement.txt @@ -0,0 +1,2 @@ +flask +flask-sqlalchemy diff --git a/examples/init_cfg_project/app/__init__.py b/examples/init_cfg_project/app/__init__.py deleted file mode 100644 index b5de85d..0000000 --- a/examples/init_cfg_project/app/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# coding: utf-8 -""" - - ~~~~~~~~ - -""" - -from flask import Flask -from config import config - -app = Flask(__name__) - - -app.config.from_object(config['default']) - - -from . import views, models, forms diff --git a/examples/init_cfg_project/config.py b/examples/init_cfg_project/config.py deleted file mode 100644 index 90594dc..0000000 --- a/examples/init_cfg_project/config.py +++ /dev/null @@ -1,47 +0,0 @@ -# coding: utf-8 -""" - config.py - ~~~~~~~~~ - - 配置文件 -""" - -import os -basedir = os.path.abspath(os.path.dirname(__file__)) - - -class Config: - """基本配置类""" - SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string' - - @staticmethod - def init_app(app): - pass - - -class DevelopmentConfig(Config): - """开发环境配置类""" - DEBUG = True - - -class TestingConfig(Config): - """测试环境配置类""" - TESTING = True - WTF_CSRF_ENABLED = False - - -class ProductionConfig(Config): - """生产环境配置类""" - - @classmethod - def init_app(cls, app): - Config.init_app(app) - - -config = { - 'development': DevelopmentConfig, - 'testing': TestingConfig, - 'production': ProductionConfig, - - 'default': DevelopmentConfig -} diff --git a/examples/init_project/requirement.txt b/examples/init_project/requirement.txt deleted file mode 100644 index e69de29..0000000 diff --git a/examples/init_sql_config/README.md b/examples/init_sql_config/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/examples/init_sql_config/app/forms.pyc b/examples/init_sql_config/app/forms.pyc deleted file mode 100644 index df84f59..0000000 Binary files a/examples/init_sql_config/app/forms.pyc and /dev/null differ diff --git a/examples/init_sql_config/app/models.pyc b/examples/init_sql_config/app/models.pyc deleted file mode 100644 index be128e4..0000000 Binary files a/examples/init_sql_config/app/models.pyc and /dev/null differ diff --git a/examples/init_sql_config/app/views.pyc b/examples/init_sql_config/app/views.pyc deleted file mode 100644 index 77c2b8a..0000000 Binary files a/examples/init_sql_config/app/views.pyc and /dev/null differ diff --git a/examples/init_sql_config/config.pyc b/examples/init_sql_config/config.pyc deleted file mode 100644 index c945a6e..0000000 Binary files a/examples/init_sql_config/config.pyc and /dev/null differ diff --git a/examples/init_sql_config/requirement.txt b/examples/init_sql_config/requirement.txt deleted file mode 100644 index e69de29..0000000 diff --git a/examples/project/README.md b/examples/project/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/examples/project/app/__init__.py b/examples/project/app/__init__.py deleted file mode 100644 index 86d2c85..0000000 --- a/examples/project/app/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# coding: utf-8 -""" - - ~~~~~~~ - -""" - -from flask import Flask - - -app = Flask(__name__) -app.config["SECRET_KEY"] = "I love mana!" # you can change it :) - - -from . import views, forms diff --git a/examples/project/app/__init__.pyc b/examples/project/app/__init__.pyc deleted file mode 100644 index 3d42ecd..0000000 Binary files a/examples/project/app/__init__.pyc and /dev/null differ diff --git a/examples/project/app/forms.py b/examples/project/app/forms.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/project/app/forms.pyc b/examples/project/app/forms.pyc deleted file mode 100644 index 49bcfc3..0000000 Binary files a/examples/project/app/forms.pyc and /dev/null differ diff --git a/examples/project/app/views.py b/examples/project/app/views.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/project/app/views.pyc b/examples/project/app/views.pyc deleted file mode 100644 index 78b31cb..0000000 Binary files a/examples/project/app/views.pyc and /dev/null differ diff --git a/examples/project/manage.py b/examples/project/manage.py deleted file mode 100644 index 8f49598..0000000 --- a/examples/project/manage.py +++ /dev/null @@ -1,47 +0,0 @@ -# coding: utf-8 - -import sys -from flask.ext.script import Manager, Shell -from flask.ext.migrate import Migrate, MigrateCommand -from flask.ext.admin import Admin -from flask.ext.admin.contrib.sqla import ModelView -from app import app, db - - -# 编码设置 -reload(sys) -sys.setdefaultencoding('utf-8') - - -manager = Manager(app) -migrate = Migrate(app, db) -admin = Admin(app, name="") - - -def make_shell_context(): - """自动加载环境""" - return dict( - app = app, - db = db - ) - - -manager.add_command("shell", Shell(make_context=make_shell_context)) -manager.add_command('db', MigrateCommand) - - -# 后台数据库管理界面 -# admin.add_view(ModelView([models], db.session)) - - -@manager.command -def test(): - """运行测试""" - import unittest - tests = unittest.TestLoader().discover('test') - unittest.TextTestRunner(verbosity=2).run(tests) - - -if __name__ == '__main__': - app.debug = True - manager.run() diff --git a/examples/project/requirement.txt b/examples/project/requirement.txt deleted file mode 100644 index e69de29..0000000 diff --git a/test.py b/test.py new file mode 100644 index 0000000..55ac395 --- /dev/null +++ b/test.py @@ -0,0 +1,7 @@ +from flask import Flask + + +app = Flask(__name__) + + +