Skip to content

Commit 1c6c606

Browse files
author
App Generator
committed
Minor Changes
1 parent e8569ac commit 1c6c606

File tree

13 files changed

+170
-100
lines changed

13 files changed

+170
-100
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dist/
1414
build/
1515
*.egg-info/
1616
*.sqlite-journal
17-
*.sqlite
17+
*.sqlite
18+
app/db.sqlite
File renamed without changes.

README.md

Lines changed: 83 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,120 @@
1-
# 1. **sample-flask-htmlx**
2-
Sample flask + htmx implementation
1+
# Flask HTMLx Sample
32

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.
94

5+
> Features:
106
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
1313

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 />
1815

19-
## 1.2. **Installation**
20-
**cloning the repository.**
16+
## **Prerequisites**
2117

22-
open terminal or command prompt and enter the following command.
18+
To get started with the application in the machine
2319

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.
2623

27-
```
24+
<br />
2825

29-
or use https:
26+
## **Installation**
3027

31-
```
32-
$ git clone https://github.com/app-generator/sample-flask-htmlx.git
33-
```
28+
> Step 1 - **cloning the repository.**
3429
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+
```
3635

37-
Create a virtual environment before installing the packages.
36+
<br />
3837

39-
```
40-
$ virtualenv env
38+
> Step 2 - Prepare Environment (create virtual environment)
4139
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
4248
```
4349

44-
Activate the virtual environment
50+
<br />
4551

46-
For unix users:
52+
> Step 3 - Install Dependencies
4753
54+
```bash
55+
$ # Install requirements
56+
$ pip3 install -r requirements.txt
4857
```
49-
$ source env/bin/activate
5058

51-
```
52-
53-
For windows users:
59+
<br />
5460

55-
```
56-
C: \Users\username\path to project > env\Scripts\activate
61+
> Step 4 - Create Database
5762
63+
```bash
64+
$ flask shell # launch Flask Shell
65+
>>>
66+
>>> from app import db
67+
>>> db.create_all()
5868
```
5969

60-
Migrate the database using python console from terminal or command prompt.
70+
<br />
6171

62-
```
63-
$ python
64-
```
65-
or
72+
> Step 4 - Create Database
6673
67-
```
68-
$ python3
74+
```bash
75+
$ flask run
6976
```
7077

71-
```
72-
>>> from app import create_app,db,models
78+
The app should be up & running on address `http://localhost:5000`
7379

74-
>>> db.create_all(app=create_app())
75-
```
80+
<br />
7681

82+
## **HTMLx**
7783

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:
8085

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/)
8389

84-
```
85-
or
90+
<br />
8691

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 -->
89102

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+
```
91116

92-
Flask server will run on port ``` 5000 ```
117+
<br />
93118

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)

app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from app import create_app,db,models
27

38
app = create_app()

app/auth.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from crypt import methods
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
26
from flask import Blueprint,render_template,url_for,redirect,request,flash
37
from werkzeug.security import generate_password_hash, check_password_hash
48
from app import db
@@ -39,7 +43,7 @@ def signup():
3943
password1 = form.password1.data
4044
password2 = form.password2.data
4145

42-
if password1!=password2:
46+
if password1 != password2:
4347
form.password2.errors.append("Passwords do not match")
4448
return redirect(url_for('auth.signup'))
4549

app/db.sqlite

0 Bytes
Binary file not shown.

app/forms.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from datetime import datetime
27
from email.policy import default
38
from flask_wtf import FlaskForm
@@ -10,7 +15,7 @@ class SignInForm(FlaskForm):
1015
email = StringField("Email", validators=[Email(
1116
"Enter a valid email address"), InputRequired("Email is required")])
1217
password = PasswordField("Password", validators=[InputRequired("Password is required"), Length(
13-
min=6, message="Password must be 6 or more characters long")])
18+
min=4, message="Password must be 4 or more characters long")])
1419
remember = BooleanField("Remember Me")
1520

1621

@@ -20,9 +25,9 @@ class SignUpForm(FlaskForm):
2025
email = StringField("Email", validators=[Email(
2126
"Enter a valid email address"), InputRequired("Email is required")])
2227
password1 = PasswordField("Password", validators=[
23-
InputRequired("Password is required"), Length(min=6)])
28+
InputRequired("Password is required"), Length(min=4)])
2429
password2 = PasswordField("Confirm Password", validators=[InputRequired(
25-
), Length(min=6, message="Password must be 6 or more characters long")])
30+
), Length(min=6, message="Password must be 4 or more characters long")])
2631

2732

2833
class ContactForm(FlaskForm):

app/main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from flask import Blueprint, redirect,render_template,url_for,request,flash
27
from flask_login import current_user,login_required
38
from app import db
@@ -7,10 +12,12 @@
712

813
main = Blueprint('main', __name__)
914

15+
# Aka HOMEPage
1016
@main.route('/',methods=['GET','POST'])
1117
def dashboard():
1218
form = ContactForm()
1319
if request.method =='POST':
20+
1421
if form.validate_on_submit():
1522
name = form.name.data
1623
email = form.email.data
@@ -20,8 +27,12 @@ def dashboard():
2027
new_message = Contact(name=name,email = email,subject=subject,message=message )
2128
db.session.add(new_message)
2229
db.session.commit()
23-
flash(message="Your feedback has been submitted",category="success")
30+
31+
flash(message="Your feedback has been submitted", category="success")
32+
33+
# Aka HOMEPage
2434
return redirect(url_for('main.dashboard'))
35+
2536
return render_template("dashboard.html",form = form)
2637

2738
@main.route('/profile')

app/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# -*- encoding: utf-8 -*-
2+
"""
3+
Copyright (c) 2019 - present AppSeed.us
4+
"""
5+
16
from email.policy import default
27
from . import db
38
from flask_login import UserMixin

app/templates/base.html

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@
2525
</head>
2626

2727
<body class="p-0 m-0">
28+
2829
<div class=" content p-0 m-0">
29-
{% block content %}
3030

31-
{% endblock content %}
31+
{% block content %}{% endblock content %}
3232

3333
</div>
34+
3435
<!-- Jquery -->
35-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
36-
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
36+
<script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous"></script>
37+
3738
<!-- Bootstrap5 bundle -->
38-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
39-
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
40-
crossorigin="anonymous"></script>
41-
</body>
39+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
4240

43-
</html>
41+
</body>
42+
</html>

0 commit comments

Comments
 (0)