MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 2 as of 2021-07-20 10:34:41
  • Python
  • DjangoREST

Django REST framework

  • https://www.django-rest-framework.org/tutorial/quickstart/#quickstart

Django REST framework is a powerful and flexible toolkit for building Web APIs.

Quickstart

  • Based on https://www.django-rest-framework.org/tutorial/quickstart/#quickstart

   1 cd ~/tmp
   2 mkdir django-rest-test
   3 cd django-rest-test
   4 sudo apt install python3-venv
   5 python3 -m venv virtenv
   6 . virtenv/bin/activate
   7 pip install djangorestframework
   8 find . virtenv/
   9 django-admin startproject tutorial . 
  10 cd tutorial
  11 django-admin startapp quickstart
  12 cd ..
  13 python manage.py migrate # sync DB 
  14 python manage.py createsuperuser --email admin@example.com --username admin # create super user, pwd: 12345678 
  15 nano tutorial/quickstart/serializers.py
  16 nano tutorial/quickstart/views.py
  17 nano tutorial/urls.py
  18 nano tutorial/settings.py
  19 python manage.py runserver
  20 # Starting development server at http://127.0.0.1:8000/
  21 curl -H 'Accept: application/json; indent=4' -u admin:12345678 

tutorial/quickstart/serializers.py

   1 from django.contrib.auth.models import User, Group
   2 from rest_framework import serializers
   3 
   4 class UserSerializer(serializers.HyperlinkedModelSerializer):
   5     class Meta:
   6         model = User
   7         fields = ['url', 'username', 'email', 'groups']
   8 
   9 class GroupSerializer(serializers.HyperlinkedModelSerializer):
  10     class Meta:
  11         model = Group
  12         fields = ['url', 'name']
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01