Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
Django rest framework getting json error for fontend api

I am using nextjs for my fontend.

When I am adding media url in my root url my api not working and throwing error FetchError: invalid json response body at http://127.0.0.1:8000/blog-api reason: Unexpected token < in JSON at position 0 but when I remove it's working.

here is my code:

urls.py

urlpatterns = [
    path('', include('api.urls')),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) #when I remove this line my api working on nextjs fontend  

Serializer.py

class BlogSerializer(serializers.ModelSerializer):
    class Meta:
        model = Blog
        fields = '__all__'

views.py

class BlogViewSet(viewsets.ModelViewSet):
    queryset = Blog.objects.all()
    serializer_class = BlogSerializer

my nextjs code for calling api:

 const url = "http://127.0.0.1:8000/blog-api";
  const headers = {
    method: "GET",
    "Content-Type": "application/json",
    Accept: "application/json",
    "User-Agent": "*",
    Authorization: "Token 8736be9dba6ccb11208a536f3531bccc686cf88d",
  };
  const res = await fetch(url, { headers: headers });

  const data = await res.json();

  console.log(data);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda