简体   繁体   中英

Delete objects in django and api

I want delete an objects from my model in django and api? can anyone help me?

The code that i wrote:

@csrf_exempt
def delete(request,news_id):
    if request.method == 'DELETE':
        News.objects.filter(id=news_id).delete()
        return JsonResponse({'message':'***'},safe=False)
    else:
        return JsonResponse({'message':'***'},safe=False)
@csrf_exempt
def delete(request,news_id):
if request.method == 'DELETE':
    news = get_object_or_404(News,news_id=news_id)
    news.delete()
    return JsonResponse({'message':'***'},safe=False)
else:
    return JsonResponse({'message':'***'},safe=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM