这是因为您没有导入JSONResponseMixin。事实上,Django没有这样的混合,这只是一个例子。
如果您真的想添加它,请将此代码添加到
class ProgramListView
from django.http import JsonResponse
class JSONResponseMixin:
"""
A mixin that can be used to render a JSON response.
"""
def render_to_json_response(self, context, **response_kwargs):
"""
Returns a JSON response, transforming 'context' to make the payload.
"""
return JsonResponse(
self.get_data(context),
**response_kwargs
)
def get_data(self, context):
"""
Returns an object that will be serialized as JSON by json.dumps().
"""
# Note: This is *EXTREMELY* naive; in reality, you'll need
# to do much more complex handling to ensure that arbitrary
# objects -- such as Django model instances or querysets
# -- can be serialized as JSON.
return context
从
https://docs.djangoproject.com/en/3.0/topics/class-based-views/mixins/#jsonresponsemixin-example
if url_parameter=='BSc':
return JsonResponse(context)