|
1 | | -# boilerplate-code-flask |
| 1 | +# [Flask Boilerplate](https://appseed.us/boilerplate-code/flask-boilerplate/) |
| 2 | + |
| 3 | +Reference codebase used by `AppSeed` in all Flask [Apps](https://appseed.us/apps/flask/) and [Dashboard](https://appseed.us/admin-dashboards/flask/) starters - the product uses an amazing design crafted by Creative-Tim. |
| 4 | + |
| 5 | +- 👉 [Flask Boilerplate](https://appseed.us/boilerplate-code/flask-boilerplate/) - `Product page` |
| 6 | +- 👉 [Flask Boilerplate](https://flask-material-kit.appseed-srv1.com/) - `LIVE App` |
| 7 | +- 👉 Free [Support](https://appseed.us/support/) via `Email` & `Discord` |
| 8 | + |
| 9 | +<br /> |
| 10 | + |
| 11 | +> 🚀 Built with [App Generator](https://appseed.us/generator/), Timestamp: `2022-06-08 12:24` |
| 12 | +
|
| 13 | +- ✅ `Up-to-date dependencies` |
| 14 | +- ✅ `Database`: `SQLite`, MySql |
| 15 | + - Silent fallback to `SQLite` |
| 16 | +- ✅ `DB Tools`: SQLAlchemy ORM, Flask-Migrate (schema migrations) |
| 17 | +- ✅ Session-Based authentication (via **flask_login**), Forms validation |
| 18 | +- ✅ Docker, `Flask-Minify` (page compression) |
| 19 | +- 🚀 `Deployment` |
| 20 | + - `CI/CD` flow via `Render` |
| 21 | + - [Flask Material Kit - Go LIVE](https://www.youtube.com/watch?v=bSFw6xrd57w) (`video presentation`) |
| 22 | + |
| 23 | +<br /> |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +<br /> |
| 28 | + |
| 29 | +## Start with `Docker` |
| 30 | + |
| 31 | +> 👉 **Step 1** - Download the code from the GH repository (using `GIT`) |
| 32 | +
|
| 33 | +```bash |
| 34 | +$ git clone https://github.com/app-generator/boilerplate-code-flask.git |
| 35 | +$ cd boilerplate-code-flask |
| 36 | +``` |
| 37 | + |
| 38 | +<br /> |
| 39 | + |
| 40 | +> 👉 **Step 2** - Start the APP in `Docker` |
| 41 | +
|
| 42 | +```bash |
| 43 | +$ docker-compose up --build |
| 44 | +``` |
| 45 | + |
| 46 | +Visit `http://localhost:5085` in your browser. The app should be up & running. |
| 47 | + |
| 48 | +<br /> |
| 49 | + |
| 50 | +## Manual Build |
| 51 | + |
| 52 | +> Download the code |
| 53 | +
|
| 54 | +```bash |
| 55 | +$ git clone https://github.com/app-generator/boilerplate-code-flask.git |
| 56 | +$ cd boilerplate-code-flask |
| 57 | +``` |
| 58 | + |
| 59 | +<br /> |
| 60 | + |
| 61 | +### 👉 Set Up for `Unix`, `MacOS` |
| 62 | + |
| 63 | +> Install modules via `VENV` |
| 64 | +
|
| 65 | +```bash |
| 66 | +$ virtualenv env |
| 67 | +$ source env/bin/activate |
| 68 | +$ pip3 install -r requirements.txt |
| 69 | +``` |
| 70 | + |
| 71 | +<br /> |
| 72 | + |
| 73 | +> Set Up Flask Environment |
| 74 | +
|
| 75 | +```bash |
| 76 | +$ export FLASK_APP=run.py |
| 77 | +$ export FLASK_ENV=development |
| 78 | +``` |
| 79 | + |
| 80 | +<br /> |
| 81 | + |
| 82 | +> Start the app |
| 83 | +
|
| 84 | +```bash |
| 85 | +$ flask run |
| 86 | +``` |
| 87 | + |
| 88 | +At this point, the app runs at `http://127.0.0.1:5000/`. |
| 89 | + |
| 90 | +<br /> |
| 91 | + |
| 92 | +### 👉 Set Up for `Windows` |
| 93 | + |
| 94 | +> Install modules via `VENV` (windows) |
| 95 | +
|
| 96 | +``` |
| 97 | +$ virtualenv env |
| 98 | +$ .\env\Scripts\activate |
| 99 | +$ pip3 install -r requirements.txt |
| 100 | +``` |
| 101 | + |
| 102 | +<br /> |
| 103 | + |
| 104 | +> Set Up Flask Environment |
| 105 | +
|
| 106 | +```bash |
| 107 | +$ # CMD |
| 108 | +$ set FLASK_APP=run.py |
| 109 | +$ set FLASK_ENV=development |
| 110 | +$ |
| 111 | +$ # Powershell |
| 112 | +$ $env:FLASK_APP = ".\run.py" |
| 113 | +$ $env:FLASK_ENV = "development" |
| 114 | +``` |
| 115 | + |
| 116 | +<br /> |
| 117 | + |
| 118 | +> Start the app |
| 119 | +
|
| 120 | +```bash |
| 121 | +$ flask run |
| 122 | +``` |
| 123 | + |
| 124 | +At this point, the app runs at `http://127.0.0.1:5000/`. |
| 125 | + |
| 126 | +<br /> |
| 127 | + |
| 128 | +### 👉 Create Users |
| 129 | + |
| 130 | +By default, the app redirects guest users to authenticate. In order to access the private pages, follow this set up: |
| 131 | + |
| 132 | +- Start the app via `flask run` |
| 133 | +- Access the `registration` page and create a new user: |
| 134 | + - `http://127.0.0.1:5000/register` |
| 135 | +- Access the `sign in` page and authenticate |
| 136 | + - `http://127.0.0.1:5000/login` |
| 137 | + |
| 138 | +<br /> |
| 139 | + |
| 140 | +## Codebase Structure |
| 141 | + |
| 142 | +The project is coded using blueprints, app factory pattern, dual configuration profile (development and production) and an intuitive structure presented bellow: |
| 143 | + |
| 144 | +```bash |
| 145 | +< PROJECT ROOT > |
| 146 | + | |
| 147 | + |-- apps/ |
| 148 | + | | |
| 149 | + | |-- home/ # A simple app that serve HTML files |
| 150 | + | | |-- routes.py # Define app routes |
| 151 | + | | |
| 152 | + | |-- authentication/ # Handles auth routes (login and register) |
| 153 | + | | |-- routes.py # Define authentication routes |
| 154 | + | | |-- models.py # Defines models |
| 155 | + | | |-- forms.py # Define auth forms (login and register) |
| 156 | + | | |
| 157 | + | |-- static/ |
| 158 | + | | |-- <css, JS, images> # CSS files, Javascripts files |
| 159 | + | | |
| 160 | + | |-- templates/ # Templates used to render pages |
| 161 | + | | |-- includes/ # HTML chunks and components |
| 162 | + | | | |-- navigation.html # Top menu component |
| 163 | + | | | |-- sidebar.html # Sidebar component |
| 164 | + | | | |-- footer.html # App Footer |
| 165 | + | | | |-- scripts.html # Scripts common to all pages |
| 166 | + | | | |
| 167 | + | | |-- layouts/ # Master pages |
| 168 | + | | | |-- base-fullscreen.html # Used by Authentication pages |
| 169 | + | | | |-- base.html # Used by common pages |
| 170 | + | | | |
| 171 | + | | |-- accounts/ # Authentication pages |
| 172 | + | | | |-- login.html # Login page |
| 173 | + | | | |-- register.html # Register page |
| 174 | + | | | |
| 175 | + | | |-- home/ # UI Kit Pages |
| 176 | + | | |-- index.html # Index page |
| 177 | + | | |-- 404-page.html # 404 page |
| 178 | + | | |-- *.html # All other pages |
| 179 | + | | |
| 180 | + | config.py # Set up the app |
| 181 | + | __init__.py # Initialize the app |
| 182 | + | |
| 183 | + |-- requirements.txt # App Dependencies |
| 184 | + | |
| 185 | + |-- .env # Inject Configuration via Environment |
| 186 | + |-- run.py # Start the app - WSGI gateway |
| 187 | + | |
| 188 | + |-- ************************************************************************ |
| 189 | +``` |
| 190 | + |
| 191 | +<br /> |
| 192 | + |
| 193 | +--- |
| 194 | +[Flask Boilerplate](https://appseed.us/boilerplate-code/flask-boilerplate/) - Open-source starter generated by **[App Generator](https://appseed.us/generator/)**. |
0 commit comments