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 :: python subprocess with environment variables 
Python :: start virtualenv 
Python :: numpy remove element 
Python :: equal sides of an array python 
Python :: pandas apply pass in arguments 
Python :: replace newline character in python 
Python :: remove particular row number in pandas 
Python :: get title attribute beautiful soup 
Python :: how to create table in a database in python 
Python :: minimum of two columns in pandas 
Python :: what is join use for in python 
Python :: python falsy values 
Python :: tkinter how to move button 
Python :: how to save a neural network pytorch 
Python :: python set comparison 
Python :: how to print x in python 
Python :: python get dictionary keys 
Python :: remove idx of list python 
Python :: python randomly chose user agent 
Python :: remove duplicates python 
Python :: python regex get string before character 
Python :: How to convert simple string in to camel case in python 
Python :: fill null values with zero python 
Python :: sorting numbers in python without sort function 
Python :: python ssh connection 
Python :: print textbox value in tkinter 
Python :: Python program to get the file size of a plain file. 
Python :: pandas merge on columns different names 
Python :: cool things to do with python 
Python :: packing and unpacking in python 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =