Skip to content

Commit 8aa1446

Browse files
committed
Added easy deploy Makefile.
1 parent e8c4652 commit 8aa1446

File tree

15 files changed

+306
-96
lines changed

15 files changed

+306
-96
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
131+
# Cached files
132132
__pycache__
133133
.DS_Store
134+
135+
# PyCharm
136+
.idea
137+
138+
# Virtual environment
139+
.venv/

Makefile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
SRCPATH := $(CURDIR)
2+
PROJECTNAME := $(shell basename $(CURDIR))
3+
4+
define HELP
5+
Manage $(PROJECTNAME). Usage:
6+
7+
make run - Run $(PROJECTNAME).
8+
make deploy - Install requirements and run app for the first time.
9+
make update - Update pip dependencies via Python Poetry.
10+
make format - Format code with Python's `Black` library.
11+
make clean - Remove cached files and lock files.
12+
endef
13+
export HELP
14+
15+
.PHONY: run restart deploy update clean help
16+
17+
18+
requirements: .requirements.txt
19+
20+
21+
.requirements.txt: requirements.txt
22+
$(shell . .venv/bin/activate && pip install -r requirements.txt)
23+
24+
25+
all help:
26+
@echo "$$HELP"
27+
28+
29+
.PHONY: run
30+
run:
31+
$(shell . .venv/bin/activate && python3 wsgi.py)
32+
33+
34+
.PHONY: deploy
35+
deploy:
36+
$(shell . ./deploy.sh)
37+
38+
39+
.PHONY: update
40+
update:
41+
poetry shell && poetry update
42+
pip freeze > requirements.txt
43+
exit
44+
45+
46+
.PHONY: format
47+
format: requirements
48+
$(shell . .venv/bin/activate)
49+
$(shell isort -rc ./)
50+
$(shell black ./)
51+
52+
53+
.PHONY: clean
54+
clean:
55+
find . -name '*.pyc' -delete
56+
find . -name '__pycache__' -delete
57+
find . -name 'poetry.lock' -delete
58+
find . -name 'Pipefile.lock' -delete

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7+
black = "*"
78

89
[packages]
910
flask = "*"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Flask Jinja Tutorial
22

3-
![Python](https://img.shields.io/badge/Python-v3.7-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
3+
![Python](https://img.shields.io/badge/Python-v3.8-blue.svg?logo=python&longCache=true&logoColor=white&colorB=5e81ac&style=flat-square&colorA=4c566a)
44
![Flask](https://img.shields.io/badge/Flask-v1.1.1-blue.svg?longCache=true&logo=flask&style=flat-square&logoColor=white&colorB=5e81ac&colorA=4c566a)
55
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
66
[![GitHub Issues](https://img.shields.io/github/issues/hackersandslackers/flask-jinja-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-jinja-tutorial/issues)
@@ -9,7 +9,7 @@
99

1010
![Flask Jinja Tutorial](https://storage.googleapis.com/hackersandslackers-cdn/2019/02/jinja@2x.jpg)
1111

12-
Source code for the accompanying tutorial found here: https://hackersandslackers.com/flask-page-templates-jinja/
12+
Source code for the accompanying tutorial found here: https://hackersandslackers.com/flask-jinja-templates/
1313

1414
## Getting Started
1515

deploy.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
if [ -d ".venv" ]
4+
then
5+
source .venv/bin/activate
6+
pip install -r requirements.txt
7+
python3 wsgi.py
8+
else
9+
python3 -m venv .venv
10+
source .venv/bin/activate
11+
python3 -m pip install --upgrade pip
12+
pip install -r requirements.txt
13+
python3 wsgi.py
14+
fi

flask_jinja_tutorial/routes.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
from flask import render_template
44

55

6-
@app.route('/')
6+
@app.route("/")
77
def home():
8-
"""Landing page."""
9-
nav = [{'name': 'Home', 'url': 'https://example.com/1'},
10-
{'name': 'About', 'url': 'https://example.com/2'},
11-
{'name': 'Pics', 'url': 'https://example.com/3'}]
12-
return render_template('home.html',
13-
nav=nav,
14-
title="Jinja Demo Site",
15-
description="Smarter page templates \
16-
with Flask & Jinja.")
8+
"""Landing page route."""
9+
nav = [
10+
{"name": "Home", "url": "https://example.com/1"},
11+
{"name": "About", "url": "https://example.com/2"},
12+
{"name": "Pics", "url": "https://example.com/3"},
13+
]
14+
return render_template(
15+
"home.html",
16+
nav=nav,
17+
title="Jinja Demo Site",
18+
description="Smarter page templates with Flask & Jinja.",
19+
)

flask_jinja_tutorial/static/css/home.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ nav a {
1313
margin-right: 30px;
1414
color: #597a96;
1515
text-decoration: none;
16-
17-
1816
}
1917

2018
.container {
5.79 KB
Loading
Loading
Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
<!doctype html>
22
<html>
33

4-
<head>
5-
<title>{{title}}</title>
4+
<head>
5+
<title>{{ title }}</title>
66
<meta charset="utf-8">
7-
<meta name="description" content="{{description}}">
8-
<link rel="shortcut icon" href="/favicon.ico">
7+
<meta name="description" content="{{ description }}">
8+
<link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.png') }}"/>
9+
<meta name="HandheldFriendly" content="True"/>
10+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover"/>
11+
<meta name="theme-color" content="#5eb9d7"/>
12+
13+
<!-- OG & Twitter metadata -->
14+
<meta property="og:site_name" content="{{ title }}"/>
15+
<meta property="og:type" content="website"/>
16+
<meta property="og:title" content="{{ title }}"/>
17+
<meta property="og:description" content="{{ description }}"/>
18+
<meta property="og:url" content="https://flaskjinja.hackersandslackers.app/"/>
19+
<meta property="og:image" content="{{ url_for('static', filename='img/flask-jinja@2x.jpg') }}"/>
20+
<meta name="twitter:title" content="{{ title }}"/>
21+
<meta name="twitter:description" content="{{ description }}"/>
22+
<meta name="twitter:url" content="https://flaskjinja.hackersandslackers.app/"/>
23+
<meta name="twitter:site" content="@hackersslackers"/>
24+
<meta name="twitter:creator" content="@toddrbirchard"/>
25+
<meta name="twitter:card" content="summary_large_image"/>
26+
<meta name="twitter:image" content="{{ url_for('static', filename='img/flask-jinja@2x.jpg') }}"/>
27+
928
{% block css %}{% endblock %}
10-
</head>
29+
</head>
1130

12-
<body>
13-
{% include 'navigation.html' %}
14-
{% block content %}{% endblock %}
15-
</body>
31+
<body>
32+
{% include 'navigation.html' %}
33+
{% block content %}{% endblock %}
34+
</body>
1635

1736
</html>

0 commit comments

Comments
 (0)