Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

286
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!