django rest framework

Post on 13-Feb-2017

181 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Django REST frameworkBlank2015/08/14

Summary•Quickstart•Settings•Model•Serializers•Views •URLs•Web view•Postman test

Quickstart# Create the project directorymkdir file_democd file_demo# Create a virtualenv to isolate our package dependencies locallyvirtualenv envsource env/bin/activate # Install Django and Django REST framework into the virtualenvpip install djangopip install djangorestframework# Set up a new project with a single applicationdjango-admin.py startproject tutorial . cd tutorialmkdir file # Save upload filesdjango-admin.py startapp quickstart# Now sync your database for the first time:python manage.py migrate# Create AdminUser and runserverpython manage.py createsuperuserblank x@x.com 1234 # (username, e-mail, password)python manage.py runserver 0.0.0.0:8669

Settings• Open file_demo/tutorial/tutorial/settings.py

permissions.IsAdminUserCreate for Basic Auth

Model• Open file_demo/tutorial/quickstart/models.py

https://docs.djangoproject.com/en/1.8/topics/db/models/https://docs.djangoproject.com/en/1.8/ref/models/fields/

ModelViews Database

Serializers• Create file_demo/tutorial/quickstart/serializers.py

http://www.django-rest-framework.org/api-guide/serializers/http://www.django-rest-framework.org/api-guide/serializers/#modelserializer

SerializerslViews Database

Views (1/3)• Open file_demo/tutorial/quickstart/views.py

http://www.django-rest-framework.org/api-guide/views/#function-based-views

Serializersl

ModelViews

Views (2/3)

http://www.django-rest-framework.org/api-guide/generic-views/

URLs• Open file_demo/tutorial/tutorial/urls.py

• Create file_demo/tutorial/quicklystart/urls.py

URLs ViewsWeb Browser

Web viewFile ListFile Detail

File Detail link

Download link

Postman testPUTPOST

Q&A

top related