asyncio in django view - django

2018-05-30 09:53:21 [exception ERROR] Internal Server Error: /of/template/team
Traceback (most recent call last):
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 56, in dispatch
return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/Users/wangchao/.virtualenvs/ENV_PY3.6_zbxtree/lib/python3.6/site-packages/django/views/generic/base.py", line 155, in get
context = self.get_context_data(**kwargs)
File "/Users/wangchao/Documents/SenseTime/sencetime_git/wangchao3/zabbixbiztree/biztree/of/views/template_team.py", line 33, in get_context_data
self.test()
File "/Users/wangchao/Documents/SenseTime/sencetime_git/wangchao3/zabbixbiztree/biztree/of/views/template_team.py", line 29, in test
result = loop.run_until_complete(asyncio.gather(*tasks))
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 596, in gather
fut = ensure_future(arg, loop=loop)
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/tasks.py", line 518, in ensure_future
loop = events.get_event_loop()
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 676, in get_event_loop
return get_event_loop_policy().get_event_loop()
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 584, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-2'.
2018-05-30 09:53:21 [basehttp ERROR] "GET /of/template/team HTTP/1.1" 500 118472
class TemplateTeamView(LoginRequiredMixin,TemplateView):
template_name = 'of/template_team.html'
def get_context_data(self, **kwargs):
loop = asyncio.get_event_loop()
tasks = [of._get_detail_template(i) for i in [1,2,3,4]]
result = loop.run_until_complete(asyncio.gather(*tasks))
context = super(TemplateTeamView, self).get_context_data(**kwargs)
context.update({"result": result})
return context
how to design calling multi APIs to gather result before render template?

Related

requests.post(url, data)error `Response`, `HttpResponse` or `HttpStreamingResponse` but received a `<class 'tuple'>`

I am doing my first Django MongoDB project and trying to save the data set in the database
here is the create method that I'm using
def create(self, request, *args, **kwargs):
try:
client = MongoClient('srv13.absolute.ag:27017')
collection = client.farmos.device
header = request.headers['Authorization']
req = json.loads(request.body)
resp = requests.post(url=f"{settings.MAINFLUX_URL}/things", data=req, params=args, headers=header)
device_id = resp.headers['Location'][8:]
req['device_token'] = device_id
collection.insert_one(req)
return {'data': 'Success'}, 200
except Exception as e:
return {'data': str(e)}, 400
But it showing an error
and the error is
Internal Server Error: /api/v1/device/
Traceback (most recent call last):
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/rest_framework/viewsets.py", line 125, in view
return self.dispatch(request, *args, **kwargs)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/home/adarsh/farmos/farmos/persistance_layer/mongodb/device_operations.py", line 53, in create
response = requests.post(url=f"{settings.MAINFLUX_URL}/things", data=json.dumps(req), headers=header)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/sessions.py", line 515, in request
prep = self.prepare_request(req)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/sessions.py", line 453, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/models.py", line 319, in prepare
self.prepare_headers(headers)
File "/home/adarsh/farmos/venv/lib/python3.6/site-packages/requests/models.py", line 451, in prepare_headers
for header in headers.items():
AttributeError: 'str' object has no attribute 'items'
I think there is a problem in this line
python
resp = requests.post(url=f"{settings.MAINFLUX_URL}/things", data=req, params=args, headers=header)
I have tried different thing changing the type of req and header to solve it but couldn't do it

Django ModelAdmin admin_order_field with nulls_last

I am trying to sort column of ModelAdmin list field with admin_order_field with nulls_last such as:
class UserProfileAdmin(admin.ModelAdmin):
def get_sum_amount(self, obj):
return obj.sum_amount
get_sum_amount.admin_order_field = F('sum_amount').desc(nulls_last=True)
But I am getting following error:
Traceback (most recent call last):
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 606, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1672, in changelist_view
cl = self.get_changelist_instance(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 744, in get_changelist_instance
sortable_by,
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 81, in __init__
self.queryset = self.get_queryset(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 436, in get_queryset
qs = qs.order_by(*ordering)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/db/models/query.py", line 1074, in order_by
obj.query.add_ordering(*field_names)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1804, in add_ordering
if not hasattr(item, 'resolve_expression') and not ORDER_PATTERN.match(item):
TypeError: expected string or bytes-like object
I am using Django 2.2. Is this issue in Django or am I doing something wrong?
This is now possible in Django starting with version 3.1.

Unicode Exception thrown when other Exception occurs

I have this strange behavior in my django project (1.11) running (example from the dev server): first I get a logging error, which might have to do with the setup
However, the real strange thing is: whenever an exception is thrown, this causes a Unicode error. I am assuming there might be a problem with the language setup or python version interference?
This is the view - I added the zero division to cause the error. When I remove it, everything works fine:
class TestView(TemplateView):
template_name = "table.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
dummy=1/0
return context
Here the error log:
--- Logging error ---
Traceback (most recent call last):
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 155, in get
context = self.get_context_data(**kwargs)
Traceback (most recent call last):
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 155, in get
context = self.get_context_data(**kwargs)
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49868)
Traceback (most recent call last):
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 155, in get
context = self.get_context_data(**kwargs)
Unhandled exception in thread started by <bound method Thread._bootstrap of <Thread(Thread-1, started daemon -173327552)>>
Traceback (most recent call last):
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/site-packages/django/views/generic/base.py", line 155, in get
context = self.get_context_data(**kwargs)
File "/home/franzritt/sky/monitoring/views.py", line 19, in get_context_data
ZeroDivisionError: division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.4/logging/__init__.py", line 978, in emit
msg = self.format(record)
File "/usr/lib/python3.4/logging/__init__.py", line 828, in format
return fmt.format(record)
File "/usr/lib/python3.4/logging/__init__.py", line 573, in format
record.exc_text = self.formatException(record.exc_info)
File "/usr/lib/python3.4/logging/__init__.py", line 523, in formatException
traceback.print_exception(ei[0], ei[1], tb, None, sio)
File "/usr/lib/python3.4/traceback.py", line 169, in print_exception
for line in _format_exception_iter(etype, value, tb, limit, chain):
File "/usr/lib/python3.4/traceback.py", line 153, in _format_exception_iter
yield from _format_list_iter(_extract_tb_iter(tb, limit=limit))
File "/usr/lib/python3.4/traceback.py", line 18, in _format_list_iter
for filename, lineno, name, line in extracted_list:
File "/usr/lib/python3.4/traceback.py", line 65, in _extract_tb_or_stack_iter
line = linecache.getline(filename, lineno, f.f_globals)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/linecache.py", line 15, in getline
lines = getlines(filename, module_globals)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/linecache.py", line 41, in getlines
return updatecache(filename, module_globals)
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/linecache.py", line 127, in updatecache
lines = fp.readlines()
File "/home/franzritt/.virtualenvs/sky/lib/python3.4/codecs.py", line 313, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 957: invalid continuation byte
I have shown here the - as I think - important parts of the error log. The logging error and the unicode error show up many more times. So my basic problem is, whenever I get an exepction I get 20 Unicode expections and 10 logging errors, which makes it difficult to find the real exception.
Your model str is not handling Unicode correctly. I recommend you put the UTF-8 encoding. To do this, put this at the beginning of you .py module/file:
# -*- coding: utf-8 -*-
If that does not work, try with:
def __str__(self):
return self.name.encode('utf8')
Or with:
class TestView(TemplateView):
template_name = "table.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
dummy=1/0
return context.encode('utf-8')

django.urls.exceptions.NoReverseMatch: Reverse for 'account_inactive' not found. 'account_inactive' is not a valid view function or pattern name

I am using django-rest-auth registration api, I overridden that by using my own SERIALIZER and model. So I am getting error.
I have tried by setting active at the time user created. But that is not working.
Let me know how to resolve this type of problem.
[12/Jan/2019 17:24:06] "POST /rest-auth/registration/ HTTP/1.1" 400 68
Internal Server Error: /rest-auth/registration/
Traceback (most recent call last):
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 46, in dispatch
return super(RegisterView, self).dispatch(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 495, in dispatch
response = self.handle_exception(exc)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 455, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/generics.py", line 192, in post
return self.create(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 65, in create
user = self.perform_create(serializer)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 81, in perform_create
None)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/utils.py", line 183, in complete_signup
signal_kwargs=signal_kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/utils.py", line 133, in perform_login
return adapter.respond_user_inactive(request, user)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/adapter.py", line 454, in respond_user_inactive
reverse('account_inactive'))
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/urls/base.py", line 90, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/urls/resolvers.py", line 622, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'account_inactive' not found. 'account_inactive' is not a valid view function or pattern name.```
this exception happend because in your User model
is_active = False .
so set True and migrate
in models.py set is_active = True
and migrate the tables

What is '_get_val_from_obj' mechanic does?

I am new to tooling job. Currently my favorite package in Django is outdated and seems no one care by now. Therefore I would like to study it.
Problem:
https://github.com/philippbosch/django-geoposition/issues/100
Traceback (most recent call last):
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/sarit/.pyenv/versions/3.6.4/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/viewsets.py", line 95, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/views.py", line 494, in dispatch
response = self.handle_exception(exc)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/views.py", line 454, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/views.py", line 491, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/mixins.py", line 22, in create
headers = self.get_success_headers(serializer.data)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/serializers.py", line 537, in data
ret = super(Serializer, self).data
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/serializers.py", line 262, in data
self._data = self.to_representation(self.instance)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/serializers.py", line 504, in to_representation
ret[field.field_name] = field.to_representation(attribute)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/lib/python3.6/site-packages/rest_framework/fields.py", line 1858, in to_representation
return self.model_field.value_to_string(obj)
File "/Users/sarit/.pyenv/versions/3.6.4/envs/poink/src/django-geoposition/geoposition/fields.py", line 50, in value_to_string
value = self._get_val_from_obj(obj)
AttributeError: 'GeopositionField' object has no attribute '_get_val_from_obj'
Official Docs:
https://docs.djangoproject.com/en/2.0/releases/2.0/
Field._get_val_from_obj() is removed.
Question:
How to solve this error?
def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
return smart_text(value)
Update:
https://github.com/pennersr/django-allauth/issues/1865
#linaskilius says
Django recommends using the Field.value_from_object() instead.
My Fork:
https://github.com/elcolie/django-geoposition