Professional Documents
Culture Documents
Building Modern Apis Using: Django 2.0
Building Modern Apis Using: Django 2.0
Modern APIs
using
Django 2.0
Salam!
I AM MASHHOOD!
3
DO YOU KNOW
DJANGO2.0?
4
DO YOU KNOW
REST?
5
GOALS
6
FORMAT
7
QUIZ
8
Introduction to
Django
9
Django 2.0
○ https://www.djangoproject.com/
○ Originally launched in 2005
○ Latest version is 2.1 (stable)
○ Maintained by Django Software
Foundation
○ Is completely open source (BSD)
10
TOOLS
○ Terminal
○ Python 3.6
○ Virtualenv
○ Pip
○ Visual Studio Code
13
QUIZ
14
FILE BREAKDOWN
15
RUN DJANGO
16
NEW DJANGO “APP”
In your eventmanager/settings.py
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
‘event’
]
18
FILE STRUCTURE
19
DJANGO MODELS
20
Example model
class Event(models.Model):
title = models.CharField(max_length=30)
description = models.CharField(max_length=30)
21
DJANGO MIGRATIONS
23
CONFIGURE ADMIN
Inside admin.py:
admin.site.register(Event)
24
DEMO
DJANGO VIEWS
○ Can we do better?
26
Introducing
Django REST
framework
27
DJANGO REST FRAMEWORK [DRF]
○ django-rest-framework.org
○ Allows you to create a web browsable API
(with GUI!)
○ Includes authentication schemes
○ Configures data serialization and
validation
28
REST PATTERN
29
DRF INSTALLATION
In eventmanager/settings.py
30
DRF MODELSERIALIZERS
class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ('title’, 'description')
32
DRF VALIDATIONS
33
DRF RENDERERS
34
DRF URLS
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include(router.urls))
]
35
VOILA, YOUR
FIRST DJANGO API
36
DRF WEB BROWSABLE API
○ Visit http://localhost:8000/api/events/
37
DRF AUTHENTICATION
38
DRF AUTHENTICATION SETTINGS
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES':
('rest_framework.permissions.IsAuthenticatedOrReadOnly',),
'DEFAULT_AUTHENTICATION_CLASSES':
('rest_framework_simplejwt.authentication.JWTAuthentication',)
}
39
DRF AUTHENTICATION URLS
urlpatterns = [
path('api/token', TokenObtainPairView.as_view()),
path('api/token/refresh', TokenRefreshView.as_view())
...
]
40
TESTING AUTHENTICATION
41
DEPLOYMENT
○ So many options!
43
DEPLOYMENT (3)
44
FINAL RECAP
45
REVIEWING COOKIECUTTER
○ https://github.com/pydanny/cookiecutter
-django
46
RESOURCES
○ https://www.youtube.com/watch?v=w0xg
J5C9Be8
○ http://www.django-rest-
framework.org/tutorial/quickstart/
○ http://blog.kevinastone.com/getting-
started-with-django-rest-framework-and-
angularjs.html
47
OPEN SOURCE
PRACTICE
github.com/recurship/
event-manager
48
Python Karachi
Group
bit.ly/python-karachi
49
THANKS!
Any questions?
slides: bit.ly/pycon18-rest
50
51
52
- Flow
- https://speakerdeck.com/phildini/api-driven-django
- Introduction about the workshop
- !! Need TAs
- About me
- Format
- Goals
- Introduciton to Django
- Introduction to Django Rest
- Introduce the project we are going to work on
- Focus on CRUD
- Setup
- pipenv
- create project
- Migrate
- Super user
- Admin panel
- Model
- Views
- Apiview
- Json return
- Serializer
- JSON RENDERer
- Browsable api renderer
- Authentication
- Testing
- Deployment (gunicorn, collectstatic, nginx)
53
Instructions for use
This template is free to use under Creative Commons Attribution license. You can keep the Credits slide or
mention SlidesCarnival and other resources used in a slide footer.
54
Hello!
I AM JAYDEN SMITH
56
“
Quotations are commonly printed
as a means of inspiration and to
invoke philosophical thoughts from
the reader.
57
THIS IS A SLIDE TITLE
58
BIG CONCEPT
Bring the attention of your audience over a
key concept using icons or illustrations
59
YOU CAN ALSO SPLIT YOUR
CONTENT
White Black
Is the color of milk and Is the color of coal,
fresh snow, the color ebony, and of outer
produced by the space. It is the darkest
combination of all the color, the result of the
colors of the visible absence of or complete
spectrum. absorption of light.
60
IN TWO OR THREE COLUMNS
61
A PICTURE IS
WORTH A
THOUSAND
WORDS
A complex idea can be
conveyed with just a
single still image, namely
making it possible to
absorb large amounts of
data quickly.
62
WANT BIG
IMPACT?
Use BIG image.
63
USE CHARTS
TO EXPLAIN YOUR IDEAS
64
OR DIAGRAMS Diagram featured by
poweredtemplate.com
TO EXPLAIN
COMPLEX IDEAS
65
AND TABLES TO COMPARE DATA
A B C
Yellow 10 20 7
Blue 30 15 10
Orange 5 24 16
66
MAPS
our office
67
89,526,124
Whoa! That’s a big number,
aren’t you proud?
68
89,526,124$
That’s a lot of money
185,244 users
And a lot of users
100%
Total success!
69
OUR PROCESS IS EASY
1. 2. 3.
first second third
70
Let’s review some concepts
71
You can copy&paste graphs from Google Sheets
72
ANDROID
PROJECT
Show and explain your
web, app or software
projects using these gadget Place your screenshot here
templates.
73
IPHONE PROJECT
Show and explain your
web, app or software
projects using these gadget
templates. Place your screenshot here
74
TABLET PROJECT
Show and explain your
web, app or software
projects using these gadget
templates. Place your screenshot here
75
Place your screenshot here
DESKTOP PROJECT
Show and explain your web, app or software projects
using these gadget templates.
76
CREDITS
Special thanks to all the people who made and released these awesome
resources for free:
○ Presentation template by SlidesCarnival
○ Photographs by Unsplash
77
PRESENTATION DESIGN
This presentations uses the following typographies and colors:
○ Titles: Montserrat
○ Body copy: Open Sans
You can download the fonts on these pages:
https://www.fontsquirrel.com/fonts/montserrat
https://www.fontsquirrel.com/fonts/open-sans
You don’t need to keep this slide in your presentation. It’s only here to serve you as a design guide if you need to create new
slides or download the fonts to edit the presentation in PowerPoint®
78
SlidesCarnival icons are editable shapes.
Examples:
79
😉
Now you can use any emoji as an icon!
And of course it resizes without losing quality and you can change the color.
✋👆👉👍👤👦👧👨👩👪💃🏃💑❤😂
😉😋😒😭👶😸🐟🍒🍔💣📌📖🔨🎃🎈
🎨🏈🏰🌏🔌🔑 and many more...
80