Django抛出下一个异常:
restframework“元组”对象没有属性“_meta”
模型
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'
看法
from .models import BDetail
from .serializers import BDetailSerializer
from rest_framework import viewsets
class BDetailList(viewsets.ModelViewSet):
queryset = BDetail.objects.all()
serializer_class = BDetailSerializer
网址
from django.conf.urls import url, include
from bdetail import views
from rest_framework import routers
router = routers.DefaultRouter()
router.register(r'bdetail', views.BDetailList)
urlpatterns = [
url(r'^', include(router.urls), name='bdetail')
]
序列化器
from .models import BDetail
from rest_framework import serializers
class BDetailSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = BDetail,
fields = ('lat', 'lng')
环境:
请求方法:GET
要求网址:http://apiix.verinmuebles.dev/v1/bdetail/
追溯:
最佳答案
您在,
序列化程序中的BDetail
模型名称之后有BDetailSerializer
。删除它,您的代码将起作用。
建议:在serializers.ModelSerializer
序列化程序中继承BDetailSerializer
而不是serializers.HyperlinkedModelSerializer
,即:
class BDetailSerializer(serializers.ModelSerializer):
class Meta:
model = BDetail
fields = ('lat', 'lng')