Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django + Flask
Search
Tzu-ping Chung
September 08, 2015
Programming
1
220
Django + Flask
Configure Flask for Django 1.8.
Tzu-ping Chung
September 08, 2015
Tweet
Share
More Decks by Tzu-ping Chung
See All by Tzu-ping Chung
Datasets: What it is, and how it was made
uranusjr
0
140
Let’s fix extras in Core Metadata 3.0
uranusjr
0
550
Python Packaging: Why Don’t You Just…?
uranusjr
1
230
這樣的開發環境沒問題嗎?
uranusjr
9
2.6k
Django After Web 2.0
uranusjr
3
2.1k
We Store Cheese in A Warehouse
uranusjr
1
460
The Python You Don’t Know
uranusjr
17
3.1k
Python and Asynchrony
uranusjr
0
380
Graphics on Raspberry Pi with Qt 5
uranusjr
0
96k
Other Decks in Programming
See All in Programming
TypeScript Language Service Plugin で CSS Modules の開発体験を改善する
mizdra
PRO
3
2.9k
DevDay2025-OracleDatabase-kernel-addressing-history
oracle4engineer
PRO
7
1.7k
Practical Domain-Driven Design - Workshop at NDC 2025
mufrid
0
140
少数精鋭エンジニアがフルスタック力を磨く理由 -そしてAI時代へ-
rebase_engineering
0
140
Take a small step beyond the api
makicamel
2
100
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
1.6k
"使いづらい" をリバースエンジニアリングする UI の読み解き方
rebase_engineering
0
120
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
2
360
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
330
ts-morph実践:型を利用するcodemodのテクニック
ypresto
1
570
「兵法」から見る質とスピード
ickx
0
230
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
0
230
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
Music & Morning Musume
bryan
47
6.6k
Visualization
eitanlees
146
16k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Fireside Chat
paigeccino
37
3.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
The Language of Interfaces
destraynor
158
25k
We Have a Design System, Now What?
morganepeng
52
7.6k
Speed Design
sergeychernyshev
30
970
Transcript
Django + Jinja2
Django Templates • The Django Template Language • How Django
loads templates
Django Templates • The Django Template Language • How Django
loads templates DTL
<ul> {% for user in users.all %}
<li> <a href="{{ user.url }}"> {{ user.username|capitalize }} </a> </li> {% endfor %} </ul>
<ul> {% for user in users.all %}
<li> <a href="{{ user.url }}"> {{ user.username|capitalize }} </a> </li> {% endfor %} </ul> (Template) Tag
<ul> {% for user in users.all %}
<li> <a href="{{ user.url }}"> {{ user.username|capitalize }} </a> </li> {% endfor %} </ul> Variable
<ul> {% for user in users.all %}
<li> <a href="{{ user.url }}"> {{ user.username|capitalize }} </a> </li> {% endfor %} </ul> Variable + Filter
The DTL • Simple syntax with few rules • Lightweight
extensions • Self-contained
But… • Awkward DSL • No scoped functions • Slow
with frequent rendering
Django 1.8 • django.template • django.template.backends
TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_DEBUG TEMPLATE_STRING_IF_INVALID TEMPLATE_DIRS TEMPLATE_LOADERS The
Language The System
TEMPLATE_CONTEXT_PROCESSORS TEMPLATE_DEBUG TEMPLATE_STRING_IF_INVALID TEMPLATE_DIRS TEMPLATE_LOADERS The
Language The System
TEMPLATES = [ {
'BACKEND': '...', 'DIRS': [], 'OPTIONS': { 'context_processors': [...], 'debug': False, 'string_if_invalid': '', }, }, ] Language-specific Setup Template-loading Setup
None
Jinja2 • Armin Ronacher (aka mitsuhiko) • Inspired by the
DTL • Standalone library • More programmer-friendly
<ul> {% for user in users.all() %}
<li> <a href="{{ user.url }}"> {{ user.username.toupper() }} </a> </li> {% endfor %} </ul> Function calling
<ul> {% for user in users.get_friends(me) %}
<li> <a href="{{ user.url }}"> {{ user.username.toupper() }} </a> </li> {% endfor %} </ul>
Settings for Jinja2 { 'BACKEND': (
'django.template.backends.' 'jinja2.Jinja2'), 'DIRS': [], 'APP_DIRS': True, },
demoapp ├── jinja2 │ └── a_jinja2_template.html ├── models.py ├── templates
│ └── a_django_template.html ├── urls.py └── views.py
demoapp ├── jinja2 │ └── a_jinja2_template.html ├── models.py ├── templates
│ └── a_django_template.html ├── urls.py └── views.py Configurable (not recommended)
Jinja2 for Django • Auto-escape on • Custom template loader
• Debug enhancements • Auto-reload • Undefined raises exceptions
But • Jinja2 is not built (just) for Web •
Web-related functionalities • Django internals
{% url 'pages:page' name=page_name %} {% static 'base/css/site.min.css' %}
{% trans 'This is my website!' %} {% csrf_token %}
https://github.com/MoritzS/jinja2-django-tags
{ 'BACKEND': ('django.template.backends.'
'jinja2.Jinja2'), 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'extensions': [ 'jdj_tags.extensions.DjangoStatic', 'jdj_tags.extensions.DjangoI18n', ] }, },
Jinja2 vs DTL • Functions vs template tags • Methods
vs filters • Extensions are loaded by project
The Flask Way • {% url_for(endpoint, **kwargs) %} • Endpoint
'static' • {% get_flashed_messages(...) %} • I18n API (already pretty similar) • {{ csrf_token() }}
To boldly go where no one has gone before.