插入轮播图
一、添加路由
urls.py中添加
path('upload_swiper/', views.upload_swiper, name='upload_swiper')
二、添加视图函数
views.py中添加
def upload_swiper(request):
if request.method == 'POST':
file = request.FILES.get('swiper_img')
url = request.POST.get('url')
title = request.POST.get('title')
models.Swiper.objects.create(image=file, img_url=url, title=title)
return redirect(reverse('upload_swiper'))
elif request.method == 'GET':
swiper_list = models.Swiper.objects.all()
return render(request, 'other/UploadSwiper.html', {'swiper_list': swiper_list})
三、轮播图功能涉及的模型层操作
毫无疑问,插入轮播图功能操作的将是轮播图的数据模型.