|
1 | | -# 1. **sample-flask-htmlx** |
2 | | -Sample flask + htmx implementation |
| 1 | +# Flask HTMLx Sample |
3 | 2 |
|
4 | | -**Table of contents** |
5 | | -- [1. **sample-flask-htmlx**](#1-sample-flask-htmlx) |
6 | | - - [1.1. **Prerequisites**](#11-prerequisites) |
7 | | - - [1.2. **Installation**](#12-installation) |
8 | | - - [1.3. **Running the application**](#13-running-the-application) |
| 3 | +Open-Source sample that uses Flask as the backend framework and HTMLx for the frontend logic. For newcomers, **Flask** is a leading web framework powered by Python and **HTMLx** is a lighweight JS utility library that allows to access AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML. |
9 | 4 |
|
| 5 | +> Features: |
10 | 6 |
|
11 | | -## 1.1. **Prerequisites** |
12 | | -To get started with the application in the machine |
| 7 | +- `Up-to-date` Dependencies |
| 8 | +- Tech Stack: |
| 9 | + - `Flask`: manages authentication and routing |
| 10 | + - `HTMLx`: manages forms submit (no JS) |
| 11 | +- Auth: Sign IN, Sign UP |
| 12 | +- Misc: SQLite DB, SQLAlchemy, Forms Validation |
13 | 13 |
|
14 | | - 1. Python3 - Make sure python3 and highr=er is installed on your system before proceeding to installation instructions. |
15 | | - 2. Git - Download and install Git.OSX and linux comes preinstalled with Git. Download and install Git in your windows machine if not installed yet. |
16 | | - 3. Pip - We will use pip to install required packages to be used in the project. |
17 | | - |
| 14 | +<br /> |
18 | 15 |
|
19 | | -## 1.2. **Installation** |
20 | | -**cloning the repository.** |
| 16 | +## **Prerequisites** |
21 | 17 |
|
22 | | -open terminal or command prompt and enter the following command. |
| 18 | +To get started with the application in the machine |
23 | 19 |
|
24 | | -``` |
25 | | -$ git clone git@github.com:app-generator/sample-flask-htmlx.git |
| 20 | +- `Python3` - Make sure python3 and highr=er is installed on your system before proceeding to installation instructions. |
| 21 | +- `Git` - Download and install Git.OSX and linux comes preinstalled with Git. Download and install Git in your windows machine if not installed yet. |
| 22 | +- `Pip` - We will use pip to install required packages to be used in the project. |
26 | 23 |
|
27 | | - ``` |
| 24 | +<br /> |
28 | 25 |
|
29 | | - or use https: |
| 26 | +## **Installation** |
30 | 27 |
|
31 | | - ``` |
32 | | - $ git clone https://github.com/app-generator/sample-flask-htmlx.git |
33 | | - ``` |
| 28 | +> Step 1 - **cloning the repository.** |
34 | 29 |
|
35 | | -**Installation instructions.** |
| 30 | +```bash |
| 31 | +$ git clone git@github.com:app-generator/sample-flask-htmlx.git |
| 32 | +// OR via HTTPS |
| 33 | +$ git clone https://github.com/app-generator/sample-flask-htmlx.git |
| 34 | +``` |
36 | 35 |
|
37 | | -Create a virtual environment before installing the packages. |
| 36 | +<br /> |
38 | 37 |
|
39 | | -``` |
40 | | -$ virtualenv env |
| 38 | +> Step 2 - Prepare Environment (create virtual environment) |
41 | 39 |
|
| 40 | +```bash |
| 41 | +$ # Virtualenv modules installation (Unix based systems) |
| 42 | +$ virtualenv env |
| 43 | +$ source env/bin/activate |
| 44 | +$ |
| 45 | +$ # Virtualenv modules installation (Windows based systems) |
| 46 | +$ # virtualenv env |
| 47 | +$ # .\env\Scripts\activate |
42 | 48 | ``` |
43 | 49 |
|
44 | | -Activate the virtual environment |
| 50 | +<br /> |
45 | 51 |
|
46 | | -For unix users: |
| 52 | +> Step 3 - Install Dependencies |
47 | 53 |
|
| 54 | +```bash |
| 55 | +$ # Install requirements |
| 56 | +$ pip3 install -r requirements.txt |
48 | 57 | ``` |
49 | | -$ source env/bin/activate |
50 | 58 |
|
51 | | -``` |
52 | | - |
53 | | -For windows users: |
| 59 | +<br /> |
54 | 60 |
|
55 | | -``` |
56 | | -C: \Users\username\path to project > env\Scripts\activate |
| 61 | +> Step 4 - Create Database |
57 | 62 |
|
| 63 | +```bash |
| 64 | +$ flask shell # launch Flask Shell |
| 65 | +>>> |
| 66 | +>>> from app import db |
| 67 | +>>> db.create_all() |
58 | 68 | ``` |
59 | 69 |
|
60 | | -Migrate the database using python console from terminal or command prompt. |
| 70 | +<br /> |
61 | 71 |
|
62 | | -``` |
63 | | -$ python |
64 | | -``` |
65 | | - or |
| 72 | +> Step 4 - Create Database |
66 | 73 |
|
67 | | -``` |
68 | | - $ python3 |
| 74 | +```bash |
| 75 | +$ flask run |
69 | 76 | ``` |
70 | 77 |
|
71 | | -``` |
72 | | ->>> from app import create_app,db,models |
| 78 | +The app should be up & running on address `http://localhost:5000` |
73 | 79 |
|
74 | | ->>> db.create_all(app=create_app()) |
75 | | -``` |
| 80 | +<br /> |
76 | 81 |
|
| 82 | +## **HTMLx** |
77 | 83 |
|
78 | | -## 1.3. **Running the application** |
79 | | -With all the bove steps done its time to run the application. The application is run with the command: |
| 84 | +All forms managed by the app use HTMLx directives. Here is the Login Form Source Code and used HTMLx directives: |
80 | 85 |
|
81 | | -``` |
82 | | -$ python app.py |
| 86 | +- [hx-swap](https://htmx.org/attributes/hx-swap/) |
| 87 | +- [hx-post](https://htmx.org/attributes/hx-post/) |
| 88 | +- [hx-target](https://htmx.org/attributes/hx-target/) |
83 | 89 |
|
84 | | -``` |
85 | | -or |
| 90 | +<br /> |
86 | 91 |
|
87 | | -``` |
88 | | -$ python3 app.py |
| 92 | +```html |
| 93 | + <form hx-swap="outerHTML" |
| 94 | + hx-post="{{ url_for('auth.signin') }}" |
| 95 | + hx-push-url="true" |
| 96 | + hx-target=".content" |
| 97 | + class="p-5 bg-white shadow mh-100 col-sm-8 col-md-6 col-lg-4" novalidate > |
| 98 | + |
| 99 | + <p class="h3 text-center p-2">SignIn</p> |
| 100 | + |
| 101 | + <!-- Truncated content --> |
89 | 102 |
|
90 | | -``` |
| 103 | + <div class="form-input p-1"> |
| 104 | + {{form.email.label}} |
| 105 | + {{form.email(class_="form-control")}} |
| 106 | + </div> |
| 107 | + |
| 108 | + <div class="form-input p-1"> |
| 109 | + {{form.password.label}} |
| 110 | + {{form.password(class_="form-control")}} |
| 111 | + </div> |
| 112 | + |
| 113 | + <button class="btn p-2 px-3 rounded btn-primary h1" type="submit">Sign In</button> |
| 114 | + </form> |
| 115 | +``` |
91 | 116 |
|
92 | | -Flask server will run on port ``` 5000 ``` |
| 117 | +<br /> |
93 | 118 |
|
94 | | -open the browser and enter the url ``` http://localhost:5000/ ``` |
| 119 | +--- |
| 120 | +**Flask HTMLx Sample** - Open-Source Sample provided by [AppSeed](https://appseed.us) |
0 commit comments