Building Modern APIs Django 2 -...
Transcript of Building Modern APIs Django 2 -...
![Page 1: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/1.jpg)
Building Modern APIs using Django 2.0
![Page 2: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/2.jpg)
Salam!I AM MASHHOOD!
I lead the engineering team at Sastaticket.pk and am GDE for Web and Angular
You can find me on twitter:
@mashhoodr2
![Page 3: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/3.jpg)
DO YOU KNOW PYTHON3.6?
3
![Page 4: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/4.jpg)
DO YOU KNOW DJANGO2.0?
4
![Page 5: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/5.jpg)
DO YOU KNOW REST?
5
![Page 6: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/6.jpg)
GOALS
○ Create models using Django○ Build API using Django REST○ Add authentication○ Understand deployment
Time is very tight so we will try to wrap up as much as possible.
6
![Page 7: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/7.jpg)
FORMAT
○ Step by step workshop○ Some theory then exercise (few minutes
will be given)○ Solution will be done afterwards○ If there is an issue, raise your hands○ If you have a question, ask the mentors
7
![Page 8: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/8.jpg)
QUIZ
Name one new feature in Python 3.6
8
![Page 9: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/9.jpg)
Introduction to Django
What powers the most powerful framework in Python?
9
![Page 10: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/10.jpg)
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
![Page 11: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/11.jpg)
TOOLS
○ Terminal○ Python 3.6○ Virtualenv○ Pip○ Visual Studio Code
Can everyone please check they have the tools on their machines?
11
![Page 12: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/12.jpg)
SETUP YOUR ENVIRONMENT
○ virtualenv -p python3 env○ source ./env/bin/activate○ python --version○ pip install django
This will install django in your environment!
12
![Page 13: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/13.jpg)
SCAFFOLDING
○ django-admin startproject eventmanager○ Create a folder with the basic project
structure○ Open the folder in VSCode
● cd eventmanager● code .
○ pip freeze > requirements.txt
13
![Page 14: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/14.jpg)
QUIZ
What is the purpose of the `__init__.py` file?
14
![Page 15: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/15.jpg)
FILE BREAKDOWN
15
![Page 16: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/16.jpg)
RUN DJANGO
○ python manage.py runserver
○ Starts the server ○ Serves your API and assets○ Auto-reloads on code changes○ Used only for dev
16
![Page 17: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/17.jpg)
NEW DJANGO “APP”
○ python manage.py startapp event
○ Creates a new folder with required files○ We will create the model, routes,
serializers in this folder
○ python manage.py migrate○ python manage.py createsuperuser --email
[email protected] --username admin 17
![Page 18: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/18.jpg)
CONFIGURE YOUR NEW APP
In your eventmanager/settings.py
INSTALLED_APPS = [
...
'django.contrib.staticfiles',
‘event’
]
18
![Page 19: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/19.jpg)
FILE STRUCTURE
19
![Page 20: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/20.jpg)
DJANGO MODELS
○ Essentially a table in your DB
○ You define how the table looks like, its columns and the types
○ We extend from Django’s models (models.Model)
20
![Page 21: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/21.jpg)
Example model
from django.db import models
class Event(models.Model):
title = models.CharField(max_length=30)
description = models.CharField(max_length=30)
21
![Page 22: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/22.jpg)
DJANGO MIGRATIONS
○ Django Migrations automatically detect the changes in the models and update the database using a single CLI command! Make migrations is only run the first time.
○ python manage.py makemigrations○ python manage.py migrate
22
![Page 23: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/23.jpg)
DJANGO ADMIN
○ Django Admin make it easy to manage the data in the tables. A nice GUI to help you manage your app.
○ We can configure it by registering the model in admin.py
23
![Page 24: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/24.jpg)
CONFIGURE ADMIN
Inside admin.py:
admin.site.register(Event)
○ Restart your server and see if you can find the model in the admin!
24
![Page 25: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/25.jpg)
DEMO
![Page 26: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/26.jpg)
DJANGO VIEWS
○ For an API Endpoint we will need:● django.views.generic.list.ListView● django.views.generic.edit.CreateView● Template File● URL update● (Possibly) a ModelForm
○ Can we do better?
26
![Page 27: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/27.jpg)
Introducing Django REST framework
A plugin to make awesome APIs
27
![Page 28: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/28.jpg)
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
![Page 29: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/29.jpg)
REST PATTERN
Representational State Transfer (REST) is a software architectural style that defines a set of constraints to be used for creating web services.
RESTful APIs are usually stateless and defined in a very specific pattern.
29
![Page 30: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/30.jpg)
DRF INSTALLATION
○ pip install djangorestframework
In eventmanager/settings.py
○ Add 'rest_framework' to your INSTALLED_APPS setting
30
![Page 31: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/31.jpg)
DRF MODELSERIALIZERS
○ Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered into JSON, XML or other content types.
○ Essentially they are the interface between Python and the data coming in.
31
![Page 32: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/32.jpg)
DRF MODELSERIALIZERS conti
from .models import Event
from rest_framework import serializers
class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ('title’, 'description')
32
![Page 33: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/33.jpg)
DRF VALIDATIONS
○ You can call `is_valid` on a serialized object○ You can check the `errors` property○ You can configure custom validations
def validate_title(self, attrs, source):
value = attrs[source]
if "django" not in value.lower():
raise serializers.ValidationError("Event post is not about Django")
return attrs
33
![Page 34: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/34.jpg)
DRF RENDERERS
○ Let’s configure our renderer!from rest_framework import viewsets
class EventView(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventSerializer
○ These 3 lines allow us to configure CRUD operations on this model.
34
![Page 35: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/35.jpg)
DRF URLS
○ Everything is almost ready, just need to configure the URLs!
from rest_framework.routers import DefaultRouter
router = DefaultRouter()
router.register(‘events', EventView)
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include(router.urls))
]35
![Page 36: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/36.jpg)
VOILA, YOUR FIRST DJANGO API
Now let’s test it out!
36
![Page 37: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/37.jpg)
DRF WEB BROWSABLE API
○ Visit http://localhost:8000/api/events/
○ Here you can play with your API, add objects, fetch then, get the JSON etc.
37
![Page 38: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/38.jpg)
DRF AUTHENTICATION
○ REST usually uses Token based authentication. So for that we will use Simple JWT library
○ pip install djangorestframework_simplejwt
38
![Page 39: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/39.jpg)
DRF AUTHENTICATION SETTINGS
Configure the authentication in settings:
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticatedOrReadOnly',),
'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework_simplejwt.authentication.JWTAuthentication',)
}
39
![Page 40: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/40.jpg)
DRF AUTHENTICATION URLS
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView)
urlpatterns = [
path('api/token', TokenObtainPairView.as_view()),
path('api/token/refresh', TokenRefreshView.as_view())
...
]
40
![Page 41: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/41.jpg)
TESTING AUTHENTICATION
○ Add option is no longer available in the Web API services.
○ We will use postman to test the permissions and authentication
41
![Page 42: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/42.jpg)
DEPLOYMENT
○ So many options!
○ You need to serve via wsgi, assets served separately via nginx/apache, Django served via Gunicorn
○ Gunicorn process should be monitored by supervisor
42
![Page 43: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/43.jpg)
DEPLOYMENT (2)
○ Configure your `STATIC_ROOT` in settings
○ python manage.py collectstatic
○ Your app is ready for deployment!
43
![Page 44: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/44.jpg)
DEPLOYMENT (3)
○ Configure nginx, gunicorn and supervisor
○ Nginx (or Apache) will use a proxy pass to the gunicorn process
○ It will also serve the static files from the `STATIC_ROOT`
44
![Page 45: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/45.jpg)
FINAL RECAP
Let’s make some awesome APIs!
45
![Page 46: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/46.jpg)
REVIEWING COOKIECUTTER
○ https://github.com/pydanny/cookiecutter-django
○ A nice scaffolding which has a lot of good things configured including Docker and
46
![Page 47: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/47.jpg)
RESOURCES
○ https://www.youtube.com/watch?v=w0xgJ5C9Be8
○ http://www.django-rest-framework.org/tutorial/quickstart/
○ http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html
47
![Page 48: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/48.jpg)
OPEN SOURCE PRACTICE
github.com/recurship/event-manager
48
![Page 49: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/49.jpg)
Python Karachi Group
bit.ly/python-karachi
49
![Page 50: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/50.jpg)
THANKS!Any questions?
You can find me at:
@mashhoodr
slides: bit.ly/pycon18-rest50
![Page 51: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/51.jpg)
51
![Page 52: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/52.jpg)
52
![Page 53: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/53.jpg)
53
- 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)
![Page 54: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/54.jpg)
Instructions for use
EDIT IN GOOGLE SLIDES
Click on the button under the presentation preview that says "Use as Google Slides Theme".
You will get a copy of this document on your Google Drive and will be able to edit, add or delete slides.
You have to be signed in to your Google account.
EDIT IN POWERPOINT®
Click on the button under the presentation preview that says "Download as PowerPoint template". You will get a .pptx file that you can edit in PowerPoint.
Remember to download and install the fonts used in this presentation (you’ll find the links to the font files needed in the Presentation design slide)
More info on how to use this template at www.slidescarnival.com/help-use-presentation-template
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
![Page 55: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/55.jpg)
Hello!I AM JAYDEN SMITH
I am here because I love to give presentations.
You can find me at:
@username
55
![Page 56: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/56.jpg)
1.TRANSITION HEADLINE
Let’s start with the first set of slides
56
![Page 57: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/57.jpg)
“Quotations are commonly printed as a means of inspiration and to
invoke philosophical thoughts from the reader.
57
![Page 58: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/58.jpg)
THIS IS A SLIDE TITLE
○ Here you have a list of items○ And some text○ But remember not to overload your
slides with content
Your audience will listen to you or read the content, but won’t do both.
58
![Page 59: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/59.jpg)
BIG CONCEPT
Bring the attention of your audience over a key concept using icons or illustrations
59
![Page 60: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/60.jpg)
White
Is the color of milk and
fresh snow, the color
produced by the
combination of all the
colors of the visible
spectrum.
YOU CAN ALSO SPLIT YOUR CONTENT
Black
Is the color of coal,
ebony, and of outer
space. It is the darkest
color, the result of the
absence of or complete
absorption of light.
60
![Page 61: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/61.jpg)
IN TWO OR THREE COLUMNS
Yellow
Is the color of gold,
butter and ripe
lemons. In the
spectrum of visible
light, yellow is found
between green and
orange.
Blue
Is the colour of the
clear sky and the deep
sea. It is located
between violet and
green on the optical
spectrum.
Red
Is the color of blood,
and because of this it
has historically been
associated with
sacrifice, danger and
courage.
61
![Page 62: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/62.jpg)
A PICTURE IS WORTH A THOUSAND WORDSA complex idea can be conveyed with just a single still image, namely making it possible to absorb large amounts of data quickly.
62
![Page 63: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/63.jpg)
WANT BIGIMPACT?
Use BIG image.
63
![Page 64: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/64.jpg)
USE CHARTSTO EXPLAIN YOUR IDEAS
GrayWhite Black
64
![Page 65: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/65.jpg)
OR DIAGRAMSTO EXPLAIN COMPLEX IDEAS
Example text.
Go ahead and replace it with your own text. Go ahead and replace it with your own text. This is an example text. Go ahead and replace it with your own text. Go ahead and replace it with your own text. Go ahead and replace it with your own text.
Example text.
Go ahead and replace it with your own text. Go ahead and replace it with your own text. This is an example text. Go ahead and replace it with your own text. Go ahead and replace it with your own text. Go ahead and replace it with your own text.
Diagram featured by poweredtemplate.com
65
![Page 66: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/66.jpg)
AND TABLES TO COMPARE DATA
A B C
Yellow 10 20 7
Blue 30 15 10
Orange 5 24 16
66
![Page 67: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/67.jpg)
MAPS
our office
67
![Page 68: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/68.jpg)
89,526,124
Whoa! That’s a big number,
aren’t you proud?
68
![Page 69: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/69.jpg)
89,526,124$That’s a lot of money
100%Total success!
185,244 usersAnd a lot of users
69
![Page 70: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/70.jpg)
OUR PROCESS IS EASY
2.second
3.third
1.first
70
![Page 71: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/71.jpg)
Let’s review some concepts
Yellow
Is the color of gold, butter and ripe
lemons. In the spectrum of visible
light, yellow is found between
green and orange.
Blue
Is the colour of the clear sky and
the deep sea. It is located between
violet and green on the optical
spectrum.
Red
Is the color of blood, and because
of this it has historically been
associated with sacrifice, danger
and courage.
Yellow
Is the color of gold, butter and
ripe lemons. In the spectrum of
visible light, yellow is found
between green and orange.
Blue
Is the colour of the clear sky and
the deep sea. It is located
between violet and green on the
optical spectrum.
Red
Is the color of blood, and because
of this it has historically been
associated with sacrifice, danger
and courage.
71
![Page 73: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/73.jpg)
ANDROID PROJECTShow and explain your web, app or software projects using these gadget templates.
Place your screenshot here
73
![Page 74: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/74.jpg)
Place your screenshot here
IPHONE PROJECTShow and explain your web, app or software projects using these gadget templates.
74
![Page 75: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/75.jpg)
Place your screenshot here
TABLET PROJECTShow and explain your web, app or software projects using these gadget templates.
75
![Page 76: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/76.jpg)
DESKTOP PROJECTShow and explain your web, app or software projects using these gadget templates.
Place your screenshot here
76
![Page 77: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/77.jpg)
CREDITS
Special thanks to all the people who made and released these awesome resources for free:
○ Presentation template by SlidesCarnival
○ Photographs by Unsplash
77
![Page 78: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/78.jpg)
PRESENTATION DESIGNThis 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
○ Teal (background) #45afdc / Teal (text) #1d98c7
○ Gold (background) #ed9e46 / Gold (text) #ffc800
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
![Page 79: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/79.jpg)
SlidesCarnival icons are editable shapes.
This means that you can:● Resize them without losing quality.● Change line color, width and style.
Isn’t that nice? :)
Examples:
79
![Page 80: Building Modern APIs Django 2 - PyConpycon.pk/static/media/uploads/presentations/pycon_pakistan_-_introduction_to_django...Create models using Django Build API using Django REST Add](https://reader030.fdocuments.net/reader030/viewer/2022040202/5e7c0602a1d6bb6df74dcbaf/html5/thumbnails/80.jpg)
Now you can use any emoji as an icon!And of course it resizes without losing quality and you can change the color.
How? Follow Google instructions https://twitter.com/googledocs/status/730087240156643328
✋👆👉👍👤👦👧👨👩👪💃🏃💑❤😂
😉😋😒😭👶😸🐟🍒🍔💣📌📖🔨🎃🎈
🎨🏈🏰🌏🔌🔑 and many more...
😉
80