Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Django rest framework update or delete

@csrf_exempt
def snippet_detail(request, pk):
    """
    Retrieve, update or delete a code snippet.
    """
    try:
        snippet = Snippet.objects.get(pk=pk)
    except Snippet.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = SnippetSerializer(snippet)
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = SnippetSerializer(snippet, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        snippet.delete()
        return HttpResponse(status=204)
Comment

PREVIOUS NEXT
Code Example
Python :: divab codechef solution 
Python :: python sqlite select column name 
Python :: print command python 
Python :: python how to replace a string in a list 
Python :: python to exe online 
Python :: tkinter python button 
Python :: plotly subplots 
Python :: max and min int in python 
Python :: python print empty line 
Python :: how to check uppercase in python 
Python :: python online practice test 
Python :: python destructure object 
Python :: run python script without .py 
Python :: python import matplotlib 
Python :: python local variables 
Python :: python function parameters default value 
Python :: python *args and **kwargs 
Python :: nibabel image 
Python :: Does np.tile Work in More Than 2 Dimensions 
Python :: python data types 
Python :: how to see truncated values in jupyter notebook 
Python :: Django Rest Retrieve API View with Slug 
Python :: os.path.dirname(__file__) 
Python :: create database python 
Python :: install requests-html in linux 
Python :: pandas.describe per group 
Python :: django get current user in form 
Python :: append two dfs 
Python :: python Python Program to Catch Multiple Exceptions in One Line 
Python :: how to pass two arg django filters 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =