在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.在apps/trade/views.py中新建获取价目表的类GetPrice:from django.shortcuts import render from rest_framework.views import APIView from rest_framework.response import Response from rest_framework.renderers import JSONRenderer,BrowsableAPIRenderer from .serializers import PriceModelSerializer,OrderModelSerializer,ShoppingCarModelSerializer from .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) 2.在apps/trade目录下新建urls.py配置路由:from django.urls import path from .views import GetPrice urlpatterns = [ path('getprice/',GetPrice.as_view()) ] 3.在gg/urls.py中加入trade的urls.py代码:from django.urls import path,include from django.views.static import serve from gg.settings import MEDIA_ROOT import xadmin urlpatterns = [ #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')) ] 2.删除广告或店铺1.在apps/ad/views.py中新建类DelUserGood:#…… from user_operation.models import Message #…… class DelUserGood(APIView): """删除广告或店铺""" renderer_classes = [JSONRenderer] # 渲染器 def get(self,request): token = request.GET.get('token') user = UserProfile.objects.filter(token=token).first() good_id=request.GET.get('goodid') # print(good_id) if user and good_id: good_id = int(good_id) good=Good.objects.filter(user=user,id=good_id).first() # print(good) title=good.title msg=Message() msg.user=user msg.content="您成功删除了"+title msg.save() Good.objects.filter(user=user,id=good_id).delete() return HttpResponse('200') else: return HttpResponse('参数不正确') 2.在apps/ad/urls.py中配置路由:from django.urls import path from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood urlpatterns = [ path('getcategory/',GetCategory.as_view()), path('createadorshop/',CreateAdOrShop.as_view()), path('uploadimg/',UpLoadImg.as_view()), path('getpubgoods/',GetPubGoods.as_view()), path('getgooddesc/',GetGoodDesc.as_view()), path('getusergoods/',GetUserGoods.as_view()), path('delusergood/',DelUserGood.as_view()), ]
|
请发表评论