Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django drf endpoint without model

# Create a custom APIView

from django.shortcuts import render

from rest_framework.views import APIView
from rest_framework.response import Response

from . import serializers
from rest_framework import status

# Create your views here.

class HelloApiView(APIView):    
    serializer_class = serializers.HelloSerializer
    def post(self, request):
        """Create a hello message with our name."""

        serializer = serializers.HelloSerializer(data=request.data)

        if serializer.is_valid():
            name = serializer.data.get('name')
            message = 'Hello {0}!'.format(name)
            return Response({'message': message})
        else:
            return Response(
                serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Comment

PREVIOUS NEXT
Code Example
Python :: geopandas clipping 
Python :: splitting x,y using iloc 
Python :: How to pass a data frame as parameter to a SQL query in Python? 
Python :: numpy move columns 
Python :: nlp generate parse tree in python 
Python :: Are angles of a parallelogram equal? 
Python :: free function in python 
Python :: discertize dara python 
Python :: islink(node1 node2) is used for 
Python :: get question mark from a word + python 
Python :: Ordering column names sensibly in pandas 
Python :: python dijkstra implementation stack 
Python :: installing intelpython3_core using anaconda 
Python :: gdal user with anaconda 
Python :: recursively count string 
Python :: how to add watermark in mp4 video using python 
Python :: Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : EOF within quoted string 
Python :: fibonacci sequence python code 
Python :: Can I convert python code to C++? 
Python :: self._flush_bg_loading_exception() 
Python :: how to read xlsx file from one directory above python 
Python :: test api register user 
Python :: find average of list via for loop python 
Python :: deine dict with same values 
Python :: how to run function when file is modified python 
Python :: python argparse one or the other 
Python :: know functionality of any function using help 
Python :: double except python 
Python :: two lists with identical entries get order 
Python :: html in nested structure 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =