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
270
1
Share
Django + Flask
Configure Flask for Django 1.8.
Tzu-ping Chung
September 08, 2015
More Decks by Tzu-ping Chung
See All by Tzu-ping Chung
Datasets: What it is, and how it was made
uranusjr
0
200
Let’s fix extras in Core Metadata 3.0
uranusjr
0
650
Python Packaging: Why Don’t You Just…?
uranusjr
1
270
這樣的開發環境沒問題嗎?
uranusjr
9
2.7k
Django After Web 2.0
uranusjr
3
2.2k
We Store Cheese in A Warehouse
uranusjr
1
500
The Python You Don’t Know
uranusjr
17
3.3k
Python and Asynchrony
uranusjr
0
430
Graphics on Raspberry Pi with Qt 5
uranusjr
0
96k
Other Decks in Programming
See All in Programming
WebAssembly を読み込むベストプラクティス 2026年春版 / Best Practices for Loading WebAssembly (Spring 2026)
petamoriken
5
1.1k
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
140
横断組織出身のQAEがインプロセスQAEでつまずいたこと・活かせたこと
ty89
0
160
oxlintはeslint/typescript-eslintを置き換えられるのか
shomafujita
1
100
エラー処理の温故知新 / history of error handling technic
ryotanakaya
7
1.9k
AI駆動開発勉強会 広島支部 第一回勉強会 AI駆動開発概要とワークショップ
hayatoshimiu
0
280
Are We Really Coding 10× Faster with AI?
kohzas
0
200
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
1
660
TSKaigi2026-静的解析への投資がAI時代のコード品質を支える ── カスタムESLintルールの設計と運用
hayatokudou
4
700
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
290
~ 秘伝のタレ化した『神スプシ』と戦う ~ 関数型パラダイムで壊れない仕組みへ
h0r15h0
1
120
書き換えて学ぶTemporal #fukts
pirosikick
2
380
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
200
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
150
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
380
Are puppies a ranking factor?
jonoalderson
1
3.4k
A Tale of Four Properties
chriscoyier
163
24k
Tell your own story through comics
letsgokoyo
1
930
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
170
Building Applications with DynamoDB
mza
96
7k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
AI: The stuff that nobody shows you
jnunemaker
PRO
7
650
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
320
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
430
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.