私はDRFを使用してこのプロジェクトを作成していますので、私は必要なデータを正常にフィルタリングしましたが、jsonとしてビューをレンダリングできません。Django RESTフレームワークフィルタリング後にJsonとして提示する方法
これは私のフィルタである:
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)
これは、件名で記事をフィルタリングし、この記事のリストを返しますが、私は取得していますという回答がこれです:
私は、次のいずれかが必要な事実を考える:それはJSON構造のこの種に取り組んで... axiosまたはフェッチ:、私はいくつかのAPIなどをフェッチ、使用してデータをフェッチするためにwan'tいずれかのレンダリングダ第二の画像のようなJSONとしてTA、または私には不明である第一の画像からデータをフェッチする方法を見つけること、それに加えて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.
私のsettings.pyがそれを可能にする:
CORS_ORIGIN_WHITELIST = (
'localhost',
'localhost:5000',
.
.
.
)
ALLOWED_HOSTS = ['localhost', ...,'http://localhost:5000']
だから私は...
CORSヘッダーを有効にする必要があります 記事を[こちら](https://stackoverflow.com/questions/35760943/how-can-i-enable-cors-on-django-rest-framework/35761458)で読んでください。 – chakri
CORSヘッダーは既に有効です。/ –