Slide 1

Slide 1 text

DJANGO TechLadies Tech Talk #2

Slide 2

Slide 2 text

ABOUT TECHLADIES ➤ TechLadies is a community-led, nonprofit initiative that introduces more women to programming. ➤ Find more information at http://www.techladies.co/ and at our Facebook page https://www.facebook.com/TechLadies/

Slide 3

Slide 3 text

ABOUT ME ➤ Vina Rianti ➤ TechLadies Bootcamp, Team AFA ➤ WordPress, not really as a "full stack" PHP Developer :( ➤ Tons of new skills Tonight.... it's about sharing some nuggets about Django! In summary: 1. Python's Virtual Environment 2. Create new Django project 3. Django Administration

Slide 4

Slide 4 text

PYTHON & PYTHON PACKAGES ➤ Python is a high-level, interpreted programming language. ➤ Readable, easy and quick to learn ➤ Used widely by academia and researchers due to large number of packages at Python Packages Index (https://pypi.python.org/pypi) ➤ Mac --> already installed, Windows --> need installation ➤ or.. https://try.jupyter.org/ for Python "on the fly"

Slide 5

Slide 5 text

PYTHON VIRTUAL ENVIRONMENT ➤ Sandbox and isolated environment for Python ➤ Manage dependencies without dilemma ➤ Keep project directory clean ➤ On Mac, do 'pip install virtualenv' ➤ Use tool called virtualenvwrapper to make it even easier. The setup that we're doing is also documented at Team AFA's Diary on http://techladies.github.io/afa-diary/prerequisites/ More info on Virtualenv at http://docs.python-guide.org/en/latest/dev/virtualenvs/ pip install virtualenvwrapper
 export WORKON_HOME=~/Envs source /usr/local/bin/virtualenvwrapper.sh ➤ Create our virtualenv: ➤ mkvirtualenv --python=/usr/local/bin/python3 myvideoblog ➤ Create our project directory: myvideoblog

Slide 6

Slide 6 text

WHAT IS DJANGO? ➤ Django (/ˈdʒæŋɡoʊ/ jang-goh) is a free and open source web application framework, written in Python. Let's just dive in ! !

Slide 7

Slide 7 text

SETUP DJANGO: INSTALL, MIGRATE, ACTION! ➤ pip install django ➤ django-admin startproject myvideoblog ➤ Open the project folder and observe the structure. ➤ Run the server: ./manage.py runserver

Slide 8

Slide 8 text

DJANGO ADMINISTRATION: QUICK AND USER FRIENDLY ➤ It's built in and no further package needed ➤ Run migration ./manage.py migrate ➤ Create your account ./manage.py createsuperuser ➤ Visit admin url at http://localhost:8000/admin/ ➤ Observe Users and Groups feature

Slide 9

Slide 9 text

GOT MORE TIME FOR MAGIC? ➤ Let's create app to handle Posts: django-admin startapp posts ➤ Plural for app, singular for model ➤ Add it to INSTALLED_APPS in settings.py ➤ Create the model in models.py from django.db import models # Create your models here. class Post(models.Model): user = models.ForeignKey('auth.User') created_on = models.DateTimeField(auto_now_add=True) title = models.CharField(max_length=512) video_url = models.URLField()

Slide 10

Slide 10 text

GOT MORE TIME FOR MAGIC? ➤ Create the migration: ./manage.py makemigrations ➤ Django will automagically detect changes and create migration scripts ➤ Migrate it: ./manage.py migrate ➤ Create PostsAdmin class for Posts in admin.py from django.contrib import admin from . import models # Register your models here. class PostsAdmin(admin.ModelAdmin): pass admin.site.register(models.Post, PostsAdmin) ➤ Refresh the admin site again!

Slide 11

Slide 11 text

WE MADE IT! ➤ Python Virtualenv and Virtualenvwrapper ➤ Django setup ➤ Django model ➤ Django administration site ➤ About 10 lines of Django code

Slide 12

Slide 12 text

THAT'S IT FOR NOW ~~ JUST KEEP SWIMMING! ➤ Special thanks to our awesome mentor Martin Brochhaus ! ➤ Join PyLadies Slack community, links at http://pyladies.sg/ ➤ Singapore Djangonauts (http://www.meetup.com/Singapore- Djangonauts/) ➤ I'm still learning too and here to help!