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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Tzu-ping Chung
September 08, 2015
Programming
270
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
200
Let’s fix extras in Core Metadata 3.0
uranusjr
0
660
Python Packaging: Why Don’t You Just…?
uranusjr
1
280
這樣的開發環境沒問題嗎?
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
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
3.9k
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
19
6.4k
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
180
Inside Stream API
skrb
1
670
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
160
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
1
100
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
180
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
340
Technical Debt: Understanding it Rightly, Engaging it Rightly #LaravelLiveJP
shogogg
0
210
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
200
sira's awesome portfolio website redesign presentation
elsirapls
0
270
AI: The stuff that nobody shows you
jnunemaker
PRO
8
700
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
460
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.3k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Agile that works and the tools we love
rasmusluckow
331
21k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
160
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
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.