http://127.0.0.1:8000/xadmin/trade/price/
from rest_framework import serializersfrom .models import Price,Order,ShoppingCarclass PriceModelSerializer(serializers.ModelSerializer): class Meta: model = Price fields="__all__"class OrderModelSerializer(serializers.ModelSerializer): class Meta: model = Order fields="__all__" class ShoppingCarModelSerializer(serializers.ModelSerializer): class Meta: model = ShoppingCar fields="__all__"
from django.shortcuts import renderfrom rest_framework.views import APIViewfrom rest_framework.response import Responsefrom rest_framework.renderers import JSONRenderer,BrowsableAPIRendererfrom .serializers import PriceModelSerializer,OrderModelSerializer,ShoppingCarModelSerializerfrom .models import Price,Order,ShoppingCar# Create your views here.class GetPrice(APIView): """ 获取价格表数据 """ renderer_classes = [JSONRenderer] # 渲染器 def get(self,request): price_list = Price.objects.all() re = PriceModelSerializer(price_list, many=True) return Response(re.data)
from django.urls import pathfrom .views import GetPriceurlpatterns = [ path(‘getprice/‘,GetPrice.as_view())]
from django.urls import path,includefrom django.views.static import servefrom gg.settings import MEDIA_ROOTimport xadminurlpatterns = [ #path(‘admin/‘, admin.site.urls), path(‘media/<path:path>‘,serve,{‘document_root‘:MEDIA_ROOT}), path(‘xadmin/‘, xadmin.site.urls), path(‘users/‘,include(‘users.urls‘)), path(‘ad/‘,include(‘ad.urls‘)), path(‘trade/‘,include(‘trade.urls‘))]