|
| 1 | +# [Flask Boilerplate](https://appseed.us/boilerplate-code/flask-boilerplate) |
| 2 | + |
| 3 | +> Template [boilerplate code](https://appseed.us/boilerplate-code) used by [AppSeed](https://appseed.us) to generate simple admin dashboards coded in [Flask](https://palletsprojects.com/p/flask/) - Features: |
| 4 | +
|
| 5 | +- UI Kit: **Quick** (Free Version) by **Webpixels** |
| 6 | +- SQLite database, Flask-SQLAlchemy ORM |
| 7 | +- Session-Based auth flow (login, register) |
| 8 | +- Deployment scripts: Docker, Gunicorn / Nginx, Heroku |
| 9 | +- Support via **Github** (issues tracker) and [Discord](https://discord.gg/fZC6hup). |
| 10 | + |
| 11 | +<br /> |
| 12 | + |
| 13 | +> Links |
| 14 | +
|
| 15 | +- [Boierplate Code Flask](https://appseed.us/boilerplate-code/flask-boilerplate) - Product page |
| 16 | +- [Boierplate Code Flask - Demo](https://boilerplate-code-flask.appseed.us/) - LIVE Demo |
| 17 | +- [Boierplate Code Flask - Docs](https://docs.appseed.us/boilerplate-code/flask/) - Documentation |
| 18 | + |
| 19 | +<br /> |
| 20 | + |
| 21 | +## Want more? Go PRO! |
| 22 | + |
| 23 | +PRO versions include **Premium UI Kits**, Lifetime updates and **24/7 LIVE Support** (via [Discord](https://discord.gg/fZC6hup)) |
| 24 | + |
| 25 | +| [Flask Datta PRO](https://appseed.us/admin-dashboards/flask-dashboard-dattaable-pro) | [Flask Material PRO](https://appseed.us/admin-dashboards/flask-dashboard-material-pro) | [Flask Volt PRO](https://appseed.us/admin-dashboards/flask-dashboard-volt-pro) | |
| 26 | +| --- | --- | --- | |
| 27 | +| [](https://appseed.us/admin-dashboards/flask-dashboard-dattaable-pro) | [](https://appseed.us/admin-dashboards/flask-dashboard-material-pro) | [](https://appseed.us/admin-dashboards/flask-dashboard-volt-pro) |
| 28 | + |
| 29 | +<br /> |
| 30 | +<br /> |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +<br /> |
| 35 | + |
| 36 | +## Build from sources |
| 37 | + |
| 38 | +```bash |
| 39 | +$ # Clone the sources |
| 40 | +$ git clone https://github.com/app-generator/boilerplate-code-flask.git |
| 41 | +$ cd boilerplate-code-flask |
| 42 | +$ |
| 43 | +$ # Virtualenv modules installation (Unix based systems) |
| 44 | +$ virtualenv env |
| 45 | +$ source env/bin/activate |
| 46 | +$ |
| 47 | +$ # Virtualenv modules installation (Windows based systems) |
| 48 | +$ # virtualenv env |
| 49 | +$ # .\env\Scripts\activate |
| 50 | +$ |
| 51 | +$ # Install requirements |
| 52 | +$ pip3 install -r requirements.txt |
| 53 | +$ |
| 54 | +$ # Set the FLASK_APP environment variable |
| 55 | +$ (Unix/Mac) export FLASK_APP=run.py |
| 56 | +$ (Windows) set FLASK_APP=run.py |
| 57 | +$ (Powershell) $env:FLASK_APP = ".\run.py" |
| 58 | +$ |
| 59 | +$ # Set up the DEBUG environment |
| 60 | +$ # (Unix/Mac) export FLASK_ENV=development |
| 61 | +$ # (Windows) set FLASK_ENV=development |
| 62 | +$ # (Powershell) $env:FLASK_ENV = "development" |
| 63 | +$ |
| 64 | +$ # Run the application |
| 65 | +$ # --host=0.0.0.0 - expose the app on all network interfaces (default 127.0.0.1) |
| 66 | +$ # --port=5000 - specify the app port (default 5000) |
| 67 | +$ flask run --host=0.0.0.0 --port=5000 |
| 68 | +$ |
| 69 | +$ # Access the app in browser: http://127.0.0.1:5000/ |
| 70 | +``` |
| 71 | + |
| 72 | +> Note: To use the app, please access the registration page and create a new user. After authentication, the app will unlock the private pages. |
| 73 | +
|
| 74 | +<br /> |
| 75 | + |
| 76 | +## Code-base structure |
| 77 | + |
| 78 | +The project has a super simple structure, represented as bellow: |
| 79 | + |
| 80 | +```bash |
| 81 | +< PROJECT ROOT > |
| 82 | + | |
| 83 | + |-- app/__init__.py |
| 84 | + |-- app/ |
| 85 | + | |-- static/ |
| 86 | + | | |-- <css, JS, images> # CSS files, Javascripts files |
| 87 | + | | |
| 88 | + | |-- templates/ |
| 89 | + | | | |
| 90 | + | | |-- includes/ # Page chunks, components |
| 91 | + | | | | |
| 92 | + | | | |-- navigation.html # Top bar |
| 93 | + | | | |-- sidebar.html # Left sidebar |
| 94 | + | | | |-- scripts.html # JS scripts common to all pages |
| 95 | + | | | |-- footer.html # The common footer |
| 96 | + | | | |
| 97 | + | | |-- layouts/ # App Layouts (the master pages) |
| 98 | + | | | | |
| 99 | + | | | |-- base.html # Used by common pages like index, UI |
| 100 | + | | | |-- base-fullscreen.html # Used by auth pages (login, register) |
| 101 | + | | | |
| 102 | + | | |-- accounts/ # Auth Pages (login, register) |
| 103 | + | | | | |
| 104 | + | | | |-- login.html # Use layout `base-fullscreen.html` |
| 105 | + | | | |-- register.html # Use layout `base-fullscreen.html` |
| 106 | + | | | |
| 107 | + | | index.html # The default page |
| 108 | + | | page-404.html # Error 404 page (page not found) |
| 109 | + | | page-500.html # Error 500 page (server error) |
| 110 | + | | *.html # All other pages provided by the UI Kit |
| 111 | + | |
| 112 | + |-- requirements.txt |
| 113 | + | |
| 114 | + |-- run.py |
| 115 | + | |
| 116 | + |-- ************************************************************************ |
| 117 | +``` |
| 118 | + |
| 119 | +<br /> |
| 120 | + |
| 121 | +## Deployment |
| 122 | + |
| 123 | +The app is provided with a basic configuration to be executed in [Docker](https://www.docker.com/), [Heroku](https://www.heroku.com/), [Gunicorn](https://gunicorn.org/), and [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/). |
| 124 | + |
| 125 | +<br /> |
| 126 | + |
| 127 | +### [Docker](https://www.docker.com/) execution |
| 128 | +--- |
| 129 | + |
| 130 | +The application can be easily executed in a docker container. The steps: |
| 131 | + |
| 132 | +> Get the code |
| 133 | +
|
| 134 | +```bash |
| 135 | +$ git clone https://github.com/app-generator/boilerplate-code-flask.git |
| 136 | +$ cd boilerplate-code-flask |
| 137 | +``` |
| 138 | + |
| 139 | +> Start the app in Docker |
| 140 | +
|
| 141 | +```bash |
| 142 | +$ sudo docker-compose pull && sudo docker-compose build && sudo docker-compose up -d |
| 143 | +``` |
| 144 | + |
| 145 | +Visit `http://localhost:5005` in your browser. The app should be up & running. |
| 146 | + |
| 147 | +<br /> |
| 148 | + |
| 149 | +### [Heroku](https://www.heroku.com/) |
| 150 | +--- |
| 151 | + |
| 152 | +Steps to deploy on **Heroku** |
| 153 | + |
| 154 | +- [Create a FREE account](https://signup.heroku.com/) on Heroku platform |
| 155 | +- [Install the Heroku CLI](https://devcenter.heroku.com/articles/getting-started-with-python#set-up) that match your OS: Mac, Unix or Windows |
| 156 | +- Open a terminal window and authenticate via `heroku login` command |
| 157 | +- Clone the sources and push the project for LIVE deployment |
| 158 | + |
| 159 | +```bash |
| 160 | +$ # Clone the source code: |
| 161 | +$ git clone https://github.com/app-generator/boilerplate-code-flask.git |
| 162 | +$ cd boilerplate-code-flask |
| 163 | +$ |
| 164 | +$ # Check Heroku CLI is installed |
| 165 | +$ heroku -v |
| 166 | +heroku/7.25.0 win32-x64 node-v12.13.0 # <-- All good |
| 167 | +$ |
| 168 | +$ # Check Heroku CLI is installed |
| 169 | +$ heroku login |
| 170 | +$ # this commaond will open a browser window - click the login button (in browser) |
| 171 | +$ |
| 172 | +$ # Create the Heroku project |
| 173 | +$ heroku create |
| 174 | +$ |
| 175 | +$ # Trigger the LIVE deploy |
| 176 | +$ git push heroku master |
| 177 | +$ |
| 178 | +$ # Open the LIVE app in browser |
| 179 | +$ heroku open |
| 180 | +``` |
| 181 | + |
| 182 | +<br /> |
| 183 | + |
| 184 | +### [Gunicorn](https://gunicorn.org/) |
| 185 | +--- |
| 186 | + |
| 187 | +Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. |
| 188 | + |
| 189 | +> Install using pip |
| 190 | +
|
| 191 | +```bash |
| 192 | +$ pip install gunicorn |
| 193 | +``` |
| 194 | +> Start the app using gunicorn binary |
| 195 | +
|
| 196 | +```bash |
| 197 | +$ gunicorn --bind 0.0.0.0:8001 run:app |
| 198 | +Serving on http://localhost:8001 |
| 199 | +``` |
| 200 | + |
| 201 | +Visit `http://localhost:8001` in your browser. The app should be up & running. |
| 202 | + |
| 203 | +<br /> |
| 204 | + |
| 205 | +### [Waitress](https://docs.pylonsproject.org/projects/waitress/en/stable/) |
| 206 | +--- |
| 207 | + |
| 208 | +Waitress (Gunicorn equivalent for Windows) is meant to be a production-quality pure-Python WSGI server with very acceptable performance. It has no dependencies except ones that live in the Python standard library. |
| 209 | + |
| 210 | +> Install using pip |
| 211 | +
|
| 212 | +```bash |
| 213 | +$ pip install waitress |
| 214 | +``` |
| 215 | +> Start the app using [waitress-serve](https://docs.pylonsproject.org/projects/waitress/en/stable/runner.html) |
| 216 | +
|
| 217 | +```bash |
| 218 | +$ waitress-serve --port=8001 run:app |
| 219 | +Serving on http://localhost:8001 |
| 220 | +``` |
| 221 | + |
| 222 | +Visit `http://localhost:8001` in your browser. The app should be up & running. |
| 223 | + |
| 224 | +<br /> |
| 225 | + |
| 226 | +## Credits & Links |
| 227 | + |
| 228 | +- [Flask Framework](https://www.palletsprojects.com/p/flask/) - The official website |
| 229 | +- [Boilerplate Code](https://appseed.us/boilerplate-code) - Index provided by **AppSeed** |
| 230 | +- [Boilerplate Code](https://github.com/app-generator/boilerplate-code) - Index published on Github |
| 231 | + |
| 232 | +<br /> |
| 233 | + |
| 234 | +--- |
| 235 | +[Flask Boilerplate](https://appseed.us/boilerplate-code/flask-boilerplate) - Provided by **AppSeed** [App Generator](https://appseed.us/app-generator). |
0 commit comments