Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Django REST framework
Blank
2015/08/14
Summary
• Quickstart
• Settings
• Model
• Serializers
• Views
• URLs
• Web view
• Postman test
Quickstart
# Create the project directory
mkdir file_demo
cd file_demo
# Create a virtualenv to isolate our package depend...
Settings
• Open file_demo/tutorial/tutorial/settings.py
permissions.IsAdminUser
Create for Basic Auth
Model
• Open file_demo/tutorial/quickstart/models.py
https://docs.djangoproject.com/en/1.8/topics/db/models/
https://docs....
Serializers
• Create file_demo/tutorial/quickstart/serializers.py
http://www.django-rest-framework.org/api-guide/serialize...
Views (1/3)
• Open file_demo/tutorial/quickstart/views.py
http://www.django-rest-framework.org/api-guide/views/#function-b...
Views (2/3)
http://www.django-rest-framework.org/api-guide/generic-views/
Views (3/3)
http://www.django-rest-framework.org/api-guide/views/#class-based-views
Ref: Viewset
http://www.django-rest-fr...
URLs
• Open file_demo/tutorial/tutorial/urls.py
• Create file_demo/tutorial/quicklystart/urls.py
URLs ViewsWeb Browser
Web view
File List
File Detail
File Detail link
Download link
Postman test
PUT
POST
Django rest framework
Django rest framework
Upcoming SlideShare
Loading in …5
×

Django rest framework

Introduce Django rest framework

  • Login to see the comments

Django rest framework

  1. 1. Django REST framework Blank 2015/08/14
  2. 2. Summary • Quickstart • Settings • Model • Serializers • Views • URLs • Web view • Postman test
  3. 3. Quickstart # Create the project directory mkdir file_demo cd file_demo # Create a virtualenv to isolate our package dependencies locally virtualenv env source env/bin/activate # Install Django and Django REST framework into the virtualenv pip install django pip install djangorestframework # Set up a new project with a single application django-admin.py startproject tutorial . cd tutorial mkdir file # Save upload files django-admin.py startapp quickstart # Now sync your database for the first time: python manage.py migrate # Create AdminUser and runserver python manage.py createsuperuser blank x@x.com 1234 # (username, e-mail, password) python manage.py runserver 0.0.0.0:8669
  4. 4. Settings • Open file_demo/tutorial/tutorial/settings.py permissions.IsAdminUser Create for Basic Auth
  5. 5. 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
  6. 6. 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
  7. 7. Views (1/3) • Open file_demo/tutorial/quickstart/views.py http://www.django-rest-framework.org/api-guide/views/#function-based-views Serializersl Model Views
  8. 8. Views (2/3) http://www.django-rest-framework.org/api-guide/generic-views/
  9. 9. Views (3/3) http://www.django-rest-framework.org/api-guide/views/#class-based-views Ref: Viewset http://www.django-rest-framework.org/api-guide/viewsets/
  10. 10. URLs • Open file_demo/tutorial/tutorial/urls.py • Create file_demo/tutorial/quicklystart/urls.py URLs ViewsWeb Browser
  11. 11. Web view File List File Detail
  12. 12. File Detail link Download link
  13. 13. Postman test PUT POST

×