Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Django

Introduction to Django

Small talk I did for our local Python Group!

Mahdi Yusuf

May 21, 2015
Tweet

More Decks by Mahdi Yusuf

Other Decks in Programming

Transcript

  1. $ django-admin startproject blogit blogit ├── blogit │ ├── __init__.py

    │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── manage.py
  2. 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)
  3. 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
  4. {% 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 %}