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
Introduction to Django
Search
Mahdi Yusuf
May 21, 2015
Programming
530
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Django
Small talk I did for our local Python Group!
Mahdi Yusuf
May 21, 2015
More Decks by Mahdi Yusuf
See All by Mahdi Yusuf
Eight Fallacies of Distributed Systems
myusuf3
0
81
Better Health Insights by Unlocking Data
myusuf3
0
130
Optimizing Your Life
myusuf3
1
170
How To Make Friends and Influence Developers
myusuf3
3
1.2k
Twisted History of Python Packaging
myusuf3
11
15k
Other Decks in Programming
See All in Programming
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
330
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
560
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
110
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
260
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
150
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
140
技術記事、 専門家としてのプログラマ、 言語化
mizchi
14
7.5k
初めてのKubernetes 本番運用でハマった話
oku053
0
130
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
どこまでゆるくて許されるのか
tk3fftk
0
500
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
330
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
470
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
460
Marketing to machines
jonoalderson
1
5.6k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
410
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
ラッコキーワード サービス紹介資料
rakko
1
4M
Transcript
Introduction to Django @myusuf3 because who reads documentation
What is Django? The D is silent.
BlogIt The future of online writing, maybe.
$ django-admin startproject blogit blogit ├── blogit │ ├── __init__.py
│ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py
$ django-admin startapp blog * be sure to add new
app in settings file
from django.db import models class Author(models.Model): name = models.CharField(max_length=50) class
Blog(models.Model): title = models.CharField(max_length=200) text = models.TextField() pub_date = models.DateTimeField('date published', auto_now_add=True,) author = models.ForeignKey(Author)
$ python manage.py makemigrations blog
Migrations for 'blog': 0001_initial.py: - Create model Author - Create
model Blog
$ python manage.py migrate
Operations to perform: Synchronize unmigrated apps: staticfiles, messages Apply all
migrations: admin, blog, contenttypes, auth, sessions Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... Running migrations: Rendering model states... DONE Applying blog.0001_initial... OK
View from Top The steward of control
def post(request, post_id): post = get_object_or_404(Blog, pk=post_id) return render(request, 'post.html',
{'post': post})
Templates and Rendering Making things look beautiful
<h1>{{ post.title }}</h1> <h4> Posted: {{ post.pub_date }}</h4> <h4>Author: {{post.author.name}}</h4>
<p> {{post.text}} </p>
Feature Request! CEO has epiphany!!
def latest(request): posts = Blog.objects.all() return render(request, 'posts.html', {'posts': posts})
{% for post in posts %} <h1>{{ post.title }}</h1> <h4>
Posted: {{ post.pub_date }}</h4> <h4>Author: {{post.author.name}}</h4> <p> {{post.text}} </p> {% endfor %}
Requirements Got a list checking it twice!
dj-database-url==0.3.0 dj-static==0.0.6 Django==1.8 gevent==1.0.1 greenlet==0.4.5 gunicorn==19.3.0 honcho==0.6.6 psycopg2==2.6 static3==0.5.1 static==1.1.1
What is Deploying? The D isn’t silent, just like in
the word difficult.
Inquiries? @myusuf3 Do something magical now!