Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Django + Flask
Search
Tzu-ping Chung
September 08, 2015
Programming
290
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
240
Let’s fix extras in Core Metadata 3.0
uranusjr
0
720
Python Packaging: Why Don’t You Just…?
uranusjr
1
300
這樣的開發環境沒問題嗎?
uranusjr
9
2.7k
Django After Web 2.0
uranusjr
3
2.3k
We Store Cheese in A Warehouse
uranusjr
1
510
The Python You Don’t Know
uranusjr
17
3.4k
Python and Asynchrony
uranusjr
0
440
Graphics on Raspberry Pi with Qt 5
uranusjr
0
96k
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
530
私なりのハーネスエンジニアリング ~独自の言語処理系の開発を通して~
seosoft
0
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
210
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
320
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
670
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
6.1k
パスワード再設定メールのURLについて知っておこう
uyuki234
0
200
最近”作らせてる” ローカルAIアプリの話
akit37
0
530
Lambda durable functionsでHuman in the Loopを楽に…楽に……
har1101
2
240
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
190
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
170
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
310
Featured
See All Featured
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
650
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
RailsConf 2023
tenderlove
30
1.6k
Unsuck your backbone
ammeep
672
58k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
970
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
960
A Modern Web Designer's Workflow
chriscoyier
699
190k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
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.