How to add React JS's Link paths to DJango URLs backend

Viewed 35

I have a project that has React as it's frontend & Django as it's backend. after i integrated React with django it works perfectly but the paths i created in React with react-router-dom doesn't load when i search the page on my browser. meaning, i can load http://127.0.0.1:8000 comfortably but if i try to search http://127.0.0.1:8000/rooms/1/UCL a path that i created with React-router-dom using it's Link, it throws an error calling Page not found how can i fix this ?

#my URL.py
from re import template
from xml.etree.ElementInclude import include
from django.contrib import admin
from django.urls import path,include
from django.views.generic import TemplateView

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/',include('api.urls')),
    path('',TemplateView.as_view(template_name='index.html')),
]

my views.py

import profile
from rest_framework.response import Response
from django.http import HttpResponse
from rest_framework.decorators import api_view
from app.models import *
from .serializers import *
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from rest_framework_simplejwt.views import TokenObtainPairView


@api_view(['GET','PUT'])
def updateRoomData(request,pk):
    try:
        message = Message.objects.get(id=pk)
    except message.DoesNotExist:
        return HttpResponse(status=404)

    if request.method=='GET':
        serializer = messageSerializer(message)
    if request.method == 'PUT':
        serializer = messageSerializer(message, data=request.data)  
        if serializer.is_valid():
            serializer.save()
        else:
            return Response(serializer.errors, status=400)
    return Response(serializer.data)

0 Answers
Related