From 95eca4df195196ce9f74c5cf3a23efe259df2931 Mon Sep 17 00:00:00 2001 From: David Carmichael Date: Sun, 11 Feb 2024 22:07:24 +0000 Subject: [PATCH] docs: updated readme with example --- README.md | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/README.md b/README.md index 1d0d9e0..86d941b 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,71 @@ Quart-Imp's main purpose is to help simplify the importing of blueprints, resources, and models. It has a few extra features built in to help with securing pages and password authentication. + +## Note + +**Quart-Flask-Patch is required to use Quart-Imp.** + +## Generate a Quart app + +```bash +quart-imp init +``` + +## Example + +```text +project/ +└── app/ + ├── blueprints/ + │ └── www/... + ├── extensions/ + │ └── __init__.py + ├── resources/ + │ ├── static/... + │ ├── templates/... + │ └── routes.py + └── __init__.py +``` + +`# app/extensions/__init__.py` + +```python +import quart_flask_patch +from flask_sqlalchemy import SQLAlchemy + +from quart_imp import Imp + +_ = quart_flask_patch + +imp = Imp() +db = SQLAlchemy() +``` + +`# app/__init__.py` + +```python +from quart import Quart + +from app.extensions import imp, db + + +def create_app(): + app = Quart(__name__, static_url_path="/") + + imp.init_app(app) + imp.import_app_resources( + files_to_import=["*"], + folders_to_import=["*"] + ) + imp.import_blueprints("blueprints") + imp.import_models("models") + + db.init_app(app) + + @app.before_serving + async def create_tables(): + db.create_all() + + return app +```