i use django framework and i have this problem with the function list in views.py under: Failed to load resource: the server responded with a status of 403 (Forbidden) and i try to fix by using csrf_exempt and api_view please any body has a solution to help me and this my views :
views.py:
import json
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
#from django.views.decorators.http import require_POST
from rest_framework.decorators import api_view
from classes import JSONResponse
from models import Folder
from serializers import FolderSerializer
def index(request):
return render(request, 'app/index.html', locals())
def api(request):
folders = Folder.objects.all()
serializer = FolderSerializer(folders, many=True)
return JSONResponse(serializer.data)
@api_view(['POST'])
@csrf_exempt
#@require_POST
def list(request):
data = json.loads(request.body)
if data['path']=="/":
rep = {"result": [
{
"name": "Dossier",
"rights": "drwxr-xr-x",
"size": "4096",
"date": "2016-03-03 15:31:40",
"type": "dir"
}, {
"name": "Fichier.txt",
"rights": "-rw-r--r--",
"size": "549923",
"date": "2016-03-03 15:31:40",
"type": "file"
}
]}
elif data['path']=="/Dossier":
rep = {"result": [
{
"name": "Said.txt",
"rights": "-rw-r--r--",
"size": "549923",
"date": "2016-03-03 15:31:40",
"type": "file"
}
]}
return JSONResponse(rep)
urls.py:
from django.conf.urls import url
urlpatterns = [
url(r'^$', 'app.views.index'),
url(r'^api/', 'app.views.api'),
url(r'^api/list', 'app.views.list'),
]
urls.py
– serg