我想通过Django URL安全地访问ElasticSearch。根据此请求,我将查找用户的令牌以获取其主键。然后我只会显示匹配的ES结果。
目前,我只想连接到我的ElasticSearch网址。它会像“代理”一样工作。
无论如何,以下返回底部回溯。如何正确设置?我需要一个序列化器
from django.http import HttpResponseRedirect
class ElasticViewSet(viewsets.ModelViewSet):
def my_view(request):
if True:
return HttpResponseRedirect('http://localhost:9200/_seach')
router.register(r'elastic', ElasticViewSet, base_name='Elastic')
Traceback:
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view
58. return view_func(*args, **kwargs)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/viewsets.py" in view
83. return self.dispatch(request, *args, **kwargs)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
477. response = self.handle_exception(exc)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/views.py" in handle_exception
437. self.raise_uncaught_exception(exc)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/views.py" in dispatch
474. response = handler(request, *args, **kwargs)
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/mixins.py" in list
40. queryset = self.filter_queryset(self.get_queryset())
File "/Users/mac1/Dev/A51/Backend/NewDJ/venv/lib/python2.7/site-packages/rest_framework/generics.py" in get_queryset
67. % self.__class__.__name__
Exception Type: AssertionError at /****/elastic/
Exception Value: 'ElasticViewSet' should either include a `queryset` attribute, or override the `get_queryset()` method.
答案 0 :(得分:0)
首先,您不需要ModelViewSet
,因为没有Model
。只需去常规ViewSet
。
其次,请花点时间考虑一下你想做什么以及你想做什么。 my_view
不是ViewSet
常规操作。返回HttpResponseRedirect
并非作为代理。