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
1
480
Introduction to Django
Small talk I did for our local Python Group!
Mahdi Yusuf
May 21, 2015
Tweet
Share
More Decks by Mahdi Yusuf
See All by Mahdi Yusuf
Eight Fallacies of Distributed Systems
myusuf3
0
33
Better Health Insights by Unlocking Data
myusuf3
0
94
Optimizing Your Life
myusuf3
1
130
How To Make Friends and Influence Developers
myusuf3
3
1k
Twisted History of Python Packaging
myusuf3
11
14k
Other Decks in Programming
See All in Programming
VS Code をプロダクトにどう取り込むか
onomax
1
340
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
0
350
try! Swift Tokyo 2024のLT枠に採択されたプロポーザルを出すときに考えていたこと
ski
0
350
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
5
870
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
8
3.9k
Ruby GitHub Packages
bkuhlmann
0
630
Anthropic Cookbook のおすすめレシピ
schroneko
6
690
はてなにおける CSS Modules、及び CSS Modules に足りないもの / CSS Modules in Hatena, and CSS Modules missing parts
mizdra
6
890
Snowflakeで眠ったデータを起こそう!
estie
0
110
AWS Application Composerで始める、 サーバーレスなデータ基盤構築 / 20240406-jawsug-hokuriku-shinkansen
kasacchiful
1
260
Java 22 Overview
kishida
1
180
Ruby Pattern Matching
bkuhlmann
0
920
Featured
See All Featured
Code Review Best Practice
trishagee
54
15k
Building Adaptive Systems
keathley
30
1.9k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
1
1.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
354
18k
Design by the Numbers
sachag
274
18k
BBQ
matthewcrist
80
8.8k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Writing Fast Ruby
sferik
620
60k
What’s in a name? Adding method to the madness
productmarketing
PRO
15
2.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
20
1.6k
Making the Leap to Tech Lead
cromwellryan
123
8.5k
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!