Closed MohamedShawky closed 7 years ago
Hey @MattBroach i follow the steps but it didnot work please help me thank you in advance
It's hard to diagnose the problem without any information. Generally, when posting about a problem like this it's useful to provide:
ok @MattBroach in viewset `class TextAPIView(MultipleModelAPIView): queryList = [ (User.objects.all(), UserSerializer), (Comment.objects.filter(style='Sonnet'), CommentSerializer),
]`
and in urls.py
router = Router.SimlpeRouter() router.register('text', TextAPIView.as_view(), base_name='text')
when i run server and visit url it didnot work
and this traceback
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/textNested/
Django Version: 1.9 Python Version: 3.4.2 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework_mongoengine', 'rest_framework', 'drf_multiple_model', 'mongoengine', 'api', 'Jmodel'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "C:\Python34\lib\site-packages\django\core\handlers\base.py" in get_response
File "C:\Python34\lib\site-packages\django\template\response.py" in render
File "C:\Python34\lib\site-packages\rest_framework\response.py" in rendered_content
File "C:\Python34\lib\site-packages\rest_framework\renderers.py" in render
File "C:\Python34\lib\site-packages\rest_framework\renderers.py" in get_context
File "C:\Python34\lib\site-packages\rest_framework\renderers.py" in get_raw_data_form
File "C:\Python34\lib\site-packages\rest_framework\generics.py" in get_serializer
File "C:\Python34\lib\site-packages\rest_framework\generics.py" in get_serializer_class
Exception Type: AssertionError at /textNested/
Exception Value: 'NsetedSerializerView' should either include a serializer_class
attribute, or override the get_serializer_class()
method.
Hmm, so I see a lot of possible problems here, but I don't think that error is actually being caused by the MultipleModelAPIView
. Here are a few things to think about:
NsetedSerializerView
, but the MultipleModelAPIView is being used in a class called TextAPIView
./textNested/
, but your router base_name is just text
. It is likely accessed at something like /text/
or /api/text/
(although it's impossible to tell without seeing the full url list)MultipleModelAPIViewset
or the MultipleModelMixin
Good luck.
Hey @MohamedShawky -- I'm not sure there's a simpler example than the one in the README. Is there a particular question that I can help you with?