还是晕。。我卡这里卡了三天了。。这是我views里面的函数。其实很简单。我数据库里面就两个列。def addlbttodb(request):
if request.method == "POST":
lbt_tp = request.FILES.get("addlbt_lbttp[0]")
lbt = Lbt()
lbt.lbtid = Lbt.objects.all().count() + 1
lbt.lbttp = lbt_tp
lbt.save()
return HttpResponseRedirect('/lunbotu/')
然后我的html里面的写的是{% for contact in contacts %}
<div class="rmid_xmxq">
<div class="title_2">{{ contact.lbtid }}</div>
<img class="title_2" src="/media/{{ contact.lbttp }}" alt="">
<div class="xmcz">
<a href="" class="xmcz_2" style="color: #7d7d7d;">查看</a>
<a href="" class="xmcz_2" style="color: #7d7d7d;">编辑</a>
<a href="" class="xmcz_2" style="color: red; text-decoration-color: red;">
删除
</a>
</div>
</div>
{% endfor %}
还有一个views的函数是我用了他那个自带的翻页的def lunbotu(request):
lbt_list = Lbt.objects.all().order_by('-lbtid')
paginator = Paginator(lbt_list, 7)
page = request.GET.get('page')
try:
contacts = paginator.page(page)
except PageNotAnInteger:
contacts = paginator.page(1)
except EmptyPage:
contacts = paginator.page(paginator.num_pages)
return render(request,'lunbotu.html',{'contacts':contacts,'lbt_list':lbt_list})
|