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 :: comparing two dataframe columns 
Python :: plot histogram in seaborn 
Python :: tkinter button command with arguments 
Python :: how to make html files open in chrome using python 
Python :: discord py get channel id by name 
Python :: pyodbc sql save pandas dataframe 
Python :: remove outliers python dataframe 
Python :: python read from stdin 
Python :: stdout.write python 
Python :: python average 
Python :: python merge list into string 
Python :: how to get the percentage accuracy of a model in python 
Python :: pandas subtract days from date 
Python :: show multiple matplotlib images 
Python :: discord.py get user input 
Python :: how to get only certain columns in pandas 
Python :: flask read form data 
Python :: printing float number python 
Python :: python3 change file permissions 
Python :: unix command in python script 
Python :: how to transpose a 2d list in python 
Python :: ursina python 
Python :: spacy load en 
Python :: argeparse can it take a type list 
Python :: pandas replace colomns location 
Python :: Ask a user for input python 
Python :: how to check if given number is binary in pytho 
Python :: python correlation between features and target 
Python :: padnas drop column 
Python :: api in python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =