1.models设置
class show_UEpojcet_img(models.Model): UEpoject_id = models.AutoField(primary_key=True, verbose_name='项目识别码') UEpoject_data = models.DateTimeField('上传时间',null=True,blank=True) UEpoject_title = models.CharField(verbose_name='项目名称', max_length=10) UEpoject_img = models.ImageField("项目封面",upload_to='upload/poject/%Y/%m/%d') UEpoject_img1 = models.ImageField("项目预览图1",upload_to='upload/poject/yulanimg/%Y/%m/%d') UEpoject_img2 = models.ImageField("项目预览图2",upload_to='upload/poject/yulanimg/%Y/%m/%d') UEpoject_img3 = models.ImageField("项目预览图3",upload_to='upload/poject/yulanimg/%Y/%m/%d') UEpoject_textmess = models.TextField("项目介绍",default="站长很赖,并没留下什么东西") def __str__(self): return self.UEpoject_title
2.views设置
def TEXT(request):#文章页面 uepoject_img = show_UEpojcet_img.objects.all() parameter = { 'uepoject_img': uepoject_img, } return render(request, "texts.html", parameter)
def get_pojectmesspage(request,UEpoject_id):#需要跳转到的文章详细页,接收前端返回的id # print("————————————————————————————————————") # print("识别码为:",UEpoject_id)通过前端点击后返回的id来进行判断并返回相应的数据 # print("————————————————————————————————————") all_ueid = show_UEpojcet_img.objects.all() for ueid in all_ueid: if ueid.UEpoject_id == UEpoject_id:判断回来的id与先前发布的id是否一致 curr_ueid = ueid print(curr_ueid) break print("--------") return render(request,"pjpage.html",{ 'curr_ueid' : curr_ueid, })
3.网页设置
<!DOCTYPE html><!--文章页面--!> {% load staticfiles %} <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> {% for ueimg in uepoject_img %} <a href="/pojectpage/{{ ueimg.UEpoject_id }}">{{ ueimg.UEpoject_title }}</a>1 {% endfor %} </body> </html>
<div class="mypojectpage_allbox"><!--文章跳转详细页--!> <div class="pjpage_img"> <img src="{{ curr_ueid.UEpoject_img.url }}" /> </div> <div class="pjpage_img"> <img src="{{ curr_ueid.UEpoject_img1.url }}" /> </div> <div class="pjpage_img"> <img src="{{ curr_ueid.UEpoject_img2.url }}" /> </div> <div class="pjpage_img"> <img src="{{ curr_ueid.UEpoject_img3.url }}" /> </div> </div>
4.urls设置
urlpatterns = [ path('admin/', admin.site.urls), path('pojectpage/<int:UEpoject_id>',get_pojectmesspage),#以文章id作为名称 path('text',TEXT) ] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)