• django实现点击文章跳转至文章详细页面


    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)
  • 相关阅读:
    用C#设置系统时间和本地时间
    在ASP.NET中使用Session常见问题集锦 收藏
    C#开源资源大汇总(2)
    漫谈ASP.NET设计中的性能优化问题
    比较著名的.net技术论坛名称(含国外的)
    在ASP.NET 2.0中,一个ASP.NET页面的生命周期
    DataGrid技巧大集合(转载)
    Silverlight经典教程书籍汇总
    Asp.Net细节性问题技巧精萃
    C#开源资源大汇总(1)
  • 原文地址:https://www.cnblogs.com/wandn/p/15516286.html
Copyright © 2020-2023  润新知