added cors headers to settings file, and changed request.post to json.loads(request.body) for frontend (#2)
I updated the - settings.py file to influce cors headers - requirements.txt to include cors-headers - Updated views/events, categories, and tags "request.post" to "json.loads(request.body)" Please approve. Co-authored-by: Madeleine <madeleine@Madeleines-MacBook-Air.local> Reviewed-on: #2 Reviewed-by: dominic <me@domdit.com>
This commit is contained in:
parent
5448fd9d3c
commit
175ffda130
5 changed files with 23 additions and 6 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.serializers.category import CategorySerializer
|
||||
|
|
@ -17,7 +19,7 @@ class CategoryView(BaseView):
|
|||
return self._build_multi_response(categories)
|
||||
|
||||
def post(self, request):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
category = Category(
|
||||
name=data.get('name'),
|
||||
description=data.get('description')
|
||||
|
|
@ -27,7 +29,7 @@ class CategoryView(BaseView):
|
|||
return self._build_response(category)
|
||||
|
||||
def put(self, request, category_id):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
|
||||
category = get_object_or_404(Category, pk=category_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.serializers.event import EventSerializer
|
||||
|
|
@ -13,7 +15,7 @@ class EventView(BaseView):
|
|||
return self._build_response(event)
|
||||
|
||||
def post(self, request):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
event = Event(
|
||||
name=data.get('name'),
|
||||
description=data.get('description'),
|
||||
|
|
@ -33,7 +35,7 @@ class EventView(BaseView):
|
|||
return self._build_response(event)
|
||||
|
||||
def put(self, request, event_id):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
|
||||
event = get_object_or_404(Event, pk=event_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.serializers.tag import TagSerializer
|
||||
|
|
@ -17,7 +19,7 @@ class TagView(BaseView):
|
|||
return self._build_multi_response(tags)
|
||||
|
||||
def post(self, request):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
tag = Tag(
|
||||
name=data.get('name'),
|
||||
)
|
||||
|
|
@ -26,7 +28,7 @@ class TagView(BaseView):
|
|||
return self._build_response(tag)
|
||||
|
||||
def put(self, request, tag_id):
|
||||
data = request.POST
|
||||
data = json.loads(request.body)
|
||||
|
||||
tag = get_object_or_404(Tag, pk=tag_id)
|
||||
tag.name = data.get('name', tag.name)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ ALLOWED_HOSTS = []
|
|||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"corsheaders",
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
|
|
@ -44,6 +45,8 @@ INSTALLED_APPS = [
|
|||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
|
|
@ -123,3 +126,9 @@ USE_TZ = True
|
|||
# https://docs.djangoproject.com/en/6.0/howto/static-files/
|
||||
|
||||
STATIC_URL = "static/"
|
||||
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://localhost:5173",
|
||||
"http://127.0.0.1:5173",
|
||||
]
|
||||
|
|
@ -10,3 +10,5 @@ psycopg-binary==3.3.4
|
|||
requests==2.34.2
|
||||
sqlparse==0.5.5
|
||||
urllib3==2.7.0
|
||||
django-cors-headers==4.0.0
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue