Skip to content

Commit 71309a5

Browse files
committed
initial commit
1 parent aabe931 commit 71309a5

File tree

13 files changed

+414
-0
lines changed

13 files changed

+414
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,7 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
132+
__pycache__
133+
.DS_Store

Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
flask = "*"
10+
11+
[requires]
12+
python_version = "3.8"

Pipfile.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Flask Jinja Tutorial
2+
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)
4+
![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)
5+
![GitHub Last Commit](https://img.shields.io/github/last-commit/google/skia.svg?style=flat-square&colorA=4c566a&colorB=a3be8c&logo=GitHub)
6+
[![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)
7+
[![GitHub Stars](https://img.shields.io/github/stars/hackersandslackers/flask-jinja-tutorial.svg?style=flat-square8&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-jinja-tutorial/stargazers)
8+
[![GitHub Forks](https://img.shields.io/github/forks/hackersandslackers/flask-jinja-tutorial.svg?style=flat-square&colorA=4c566a&logo=GitHub&colorB=ebcb8b)](https://github.com/hackersandslackers/flask-jinja-tutorial/network)
9+
10+
![Flask Jinja Tutorial](https://storage.googleapis.com/hackersandslackers-cdn/2019/02/jinja@2x.jpg)
11+
12+
Source code for the accompanying tutorial found here: https://hackersandslackers.com/flask-page-templates-jinja/
13+
14+
## Getting Started
15+
16+
Installation is recommended with Pipenv:
17+
18+
```shell
19+
$ git clone https://github.com/hackersandslackers/flask-jinja-tutorial.git
20+
$ cd flask-jinja-tutorial
21+
$ pipenv shell
22+
$ pipenv update
23+
$ flask run
24+
```
25+
26+
Alternatively, try installing via `setup.py`:
27+
28+
```shell
29+
$ git clone https://github.com/hackersandslackers/flask-jinja-tutorial.git
30+
$ cd flask-jinja-tutorial
31+
$ python3 setup.py install
32+
$ flask run
33+
```
34+
-----
35+
36+
**Hackers and Slackers** tutorials are free of charge. If you found this tutorial helpful, a [small donation](https://www.buymeacoffee.com/hackersslackers) would be greatly appreciated to keep us in business. All proceeds go towards coffee, and all coffee goes towards more content.

flask_jinja_tutorial/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Basic Flask Application."""
2+
from flask import Flask
3+
4+
5+
def create_app():
6+
"""Construct the core application."""
7+
app = Flask(__name__, template_folder="templates")
8+
9+
with app.app_context():
10+
from . import routes
11+
12+
return app

flask_jinja_tutorial/routes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Route declaration."""
2+
from flask import current_app as app
3+
from flask import render_template
4+
5+
6+
@app.route('/')
7+
def home():
8+
"""Landing page."""
9+
links = [{'name': 'Link 1', 'url': 'https://example.com/1'},
10+
{'name': 'Link 2', 'url': 'https://example.com/2'},
11+
{'name': 'Link 2', 'url': 'https://example.com/3'}]
12+
return render_template('home.html',
13+
links=links,
14+
title="Jinja Demo Site",
15+
description="Smarter page templates \
16+
with Flask & Jinja.")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{% extends 'layout.html' %}
2+
3+
{% block css %}
4+
<link href="{{ url_for('static', filename='css/home.css') }}" rel="stylesheet">
5+
{% endblock %}
6+
7+
{% block content %}
8+
<div class="container">
9+
<h1>{{title}}</h1>
10+
<p>{{description}}</p>
11+
</div>
12+
{% endblock %}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<title>{{title}}</title>
6+
<meta charset="utf-8">
7+
<meta name="description" content="{{description}}">
8+
<link rel="shortcut icon" href="/favicon.ico">
9+
{% block css %}{% endblock %}
10+
</head>
11+
12+
<body>
13+
{% include 'navigation.html' %}
14+
{% block content %}{% endblock %}
15+
</body>
16+
17+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<header>
2+
<nav>
3+
{% for link in links %}
4+
<a href="{{ link.url }}">{{ link.name }}</a>
5+
{% endfor %}
6+
</nav>
7+
</header>

poetry.lock

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)