I have this project using DRF...so I have sucessfully filtered the data that I wanted, but can't render a view as json to it.
This is my filter:
class ArticleFilteredList(generics.ListAPIView):
serializer_class = ArticleSerializer
def get_queryset(self):
"""
This view should return a list of all the purchases for
the user as determined by the username portion of the URL.
"""
subject = self.kwargs['subject']
return Article.objects.filter(subject__name=subject)
It filters Articles by Subject, and then returns a list of this Articles, but the response that I'm getting is this:
The problem is, I wan't to fetch the data using, some fetch API like: axios or fetch...It worked on this kind of Json structure:
Given the facts I need one of the following: either render the data as json like the second image, or find a way to fetch data from the first image, which is unknown to me, plus it fires this error with CORS:
XMLHttpRequest cannot load http://localhost:8000/news/articles/POLITICS.
Redirect from 'http://localhost:8000/news/articles/POLITICS' to
'http://localhost:8000/news/articles/POLITICS/' has been blocked by CORS
policy: No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:5000' is therefore not allowed access.
My settings.py allows it:
CORS_ORIGIN_WHITELIST = (
'localhost',
'localhost:5000',
.
.
.
)
ALLOWED_HOSTS = ['localhost', ...,'http://localhost:5000']
So I'm not really sure what's happening...