Slide 1

Slide 1 text

Introduction to Django @myusuf3 because who reads documentation

Slide 2

Slide 2 text

What is Django? The D is silent.

Slide 3

Slide 3 text

BlogIt The future of online writing, maybe.

Slide 4

Slide 4 text

$ django-admin startproject blogit blogit ├── blogit │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py

Slide 5

Slide 5 text

$ django-admin startapp blog * be sure to add new app in settings file

Slide 6

Slide 6 text

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)

Slide 7

Slide 7 text

$ python manage.py makemigrations blog

Slide 8

Slide 8 text

Migrations for 'blog': 0001_initial.py: - Create model Author - Create model Blog

Slide 9

Slide 9 text

$ python manage.py migrate

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

View from Top The steward of control

Slide 12

Slide 12 text

def post(request, post_id): post = get_object_or_404(Blog, pk=post_id) return render(request, 'post.html', {'post': post})

Slide 13

Slide 13 text

Templates and Rendering Making things look beautiful

Slide 14

Slide 14 text

{{ post.title }}

Posted: {{ post.pub_date }}

Author: {{post.author.name}}

{{post.text}}

Slide 15

Slide 15 text

Feature Request! CEO has epiphany!!

Slide 16

Slide 16 text

def latest(request): posts = Blog.objects.all() return render(request, 'posts.html', {'posts': posts})

Slide 17

Slide 17 text

{% for post in posts %}

{{ post.title }}

Posted: {{ post.pub_date }}

Author: {{post.author.name}}

{{post.text}}

{% endfor %}

Slide 18

Slide 18 text

Requirements Got a list checking it twice!

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

What is Deploying? The D isn’t silent, just like in the word difficult.

Slide 21

Slide 21 text

Inquiries? @myusuf3 Do something magical now!