Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django rest framework

pip install djangorestframework


#Add 'rest_framework' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
    ...
    'rest_framework',
]
#If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py file.

urlpatterns = [
    ...
    path('api-auth/', include('rest_framework.urls'))
]
Comment

django rest framework

### 1- install libraries ###
pip install djangorestframework
pip install markdown       # Markdown support for the browsable API.
pip install django-filter  # Filtering support

### 2- add rest framework to installed apps in settings.py ###
INSTALLED_APPS = [
    ...
    'rest_framework',
]

### 3- create serializers.py file (used to process python objects into json format) ###
from rest_framework import serializers
from .models import Drink

class ProductSerializer(serializers.ModelSerializer):
    class Meta:
        model = Product
        fields = ['id', 'name', 'description']
        
### 4- in views.py create the view that handle the whole process ###
from django.http import JsonResponse
from .models import Product
from .serializers import ProductSerializer

def getProductsAsJson(request):
    products = Product.objects.all()
    serializer = ProductSerializer(product, many=True)
    return JsonResponse(serializer.data, safe=False)
  
### 5- you can now add this view in urls.py and try it ###
Comment

django rest framework

pip install djangorestframework


#Add 'rest_framework' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
    ...
    'rest_framework',
]
#If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root urls.py file.

urlpatterns = [
    ...
    path('api-auth/', include('rest_framework.urls'))
]
Comment

django rest framework

$ pipenv install djangorestframework
# or
pip install djangorestframework
Comment

django rest framework

# created by eastcoders swahili
from rest_framework.decorators import api_view
from rest_framework.response import Response
# Create your views here.


@api_view()
def say_hellow(request):
    return Response("ok")
Comment

PREVIOUS NEXT
Code Example
Python :: read csv without header pandas 
Python :: pandas df row count 
Python :: string startswith python 
Python :: time until 2021 
Python :: calculate nth prime number python 
Python :: python transpose list of lists 
Python :: python reverse linked list 
Python :: how to count special values in data in python 
Python :: pi in python math 
Python :: python set remove 
Python :: Concatenate Item in list to strings 
Python :: pdf to text python 
Python :: datetime utcnow 
Python :: prevent list index out of range python 
Python :: apostrophe in python 
Python :: pasal 
Python :: rum system commands python 
Python :: play mp3 file python 
Python :: print output python to file 
Python :: starting vscode on colab 
Python :: django and operator 
Python :: jupyter upload folder 
Python :: add custom field to serializer 
Python :: ImportError: No module named flask 
Python :: beautifulsoup remove element 
Python :: cv2.threshold binary 
Python :: tdmq python 
Python :: python calculate angle between two points 
Python :: datetime.datetime.fromtimestamp() 
Python :: python numpy array replace nan with string 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =