python - restframework 'tuple' object has no attribute '_meta' -


django throws next exception:

restframework 'tuple' object has no attribute '_meta'

model

class bdetail(models.model):    lat = models.floatfield(blank=true, null=true)    lng = models.floatfield(blank=true, null=true)     class meta:        # managed = false        db_table = 'b_detail' 

view

from .models import bdetail .serializers import bdetailserializer rest_framework import viewsets  class bdetaillist(viewsets.modelviewset):         queryset = bdetail.objects.all()         serializer_class = bdetailserializer 

urls

from django.conf.urls import url, include bdetail import views rest_framework import routers  router = routers.defaultrouter() router.register(r'bdetail', views.bdetaillist)  urlpatterns = [     url(r'^', include(router.urls), name='bdetail') ] 

serializers

from .models import bdetail rest_framework import serializers  class bdetailserializer(serializers.hyperlinkedmodelserializer):     class meta:         model = bdetail,         fields = ('lat', 'lng') 

environment:

request method: request url: http://apiix.verinmuebles.dev/v1/bdetail/

traceback:

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner 39. response = get_response(request)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view 58. return view_func(*args, **kwargs)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/viewsets.py" in view 87. return self.dispatch(request, *args, **kwargs)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 474. response = self.handle_exception(exc)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/views.py" in handle_exception 434. self.raise_uncaught_exception(exc)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 471. response = handler(request, *args, **kwargs)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/mixins.py" in list 45. return self.get_paginated_response(serializer.data)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in data 701. ret = super(listserializer, self).data

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in data 240. self._data = self.to_representation(self.instance)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in to_representation 619. self.child.to_representation(item) item in iterable

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in to_representation 460. fields = self._readable_fields

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/django/utils/functional.py" in get 35. res = instance.dict[self.name] = self.func(instance)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in _readable_fields 354. field field in self.fields.values()

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in fields 340. key, value in self.get_fields().items():

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/serializers.py" in get_fields 946. info = model_meta.get_field_info(model)

file "/var/www/verinmuebles/current/env/api/local/lib/python2.7/site-packages/rest_framework/utils/model_meta.py" in get_field_info 36. opts = model._meta.concrete_model._meta

exception type: attributeerror @ /v1/bdetail/ exception value: 'tuple' object has no attribute '_meta'

you having , after name of bdetail model in bdetailserializer serializer. remove , code work.

suggestion: inherit serializers.modelserializer in bdetailserializer serializer instead of serializers.hyperlinkedmodelserializer i.e. :

class bdetailserializer(serializers.modelserializer):     class meta:         model = bdetail         fields = ('lat', 'lng') 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -