• 1.3.2 查看文章内容


    目录

    1.编辑 blog/views.py

    from django.shortcuts import render,get_object_or_404
    from .models import BlogArticles
    
    # Create your views here.
    def blog_title(request):
        blogs = BlogArticles.objects.all()
        #print(blogs)
        return render(request,"blog/titles.html",{"blogs":blogs})
    
    def blog_article(request,article_id):
        article=get_object_or_404(BlogArticles,id=article_id)
        pub=article.publish
        #return render_to_response("content.html",{"article":article,"publish":pub})
        return render(request,"blog/content.html",{"article":article,"publish":pub})

     2.编辑 templates/blog/content.html

    {% extends "base.html" %}
    {% block title %} block  article{% endblock %}
    {% block content %}
    <div class="row text-center vertical-middle-sm">
            <h1>{{article.title}}</h1>
    </div>
    <div class="row">
            <div class="col-xs-12 col-md-8">
                    <p class="text=-center"><span>{{article.author.username}}</span><span style="margin-left:20px">{{article.publish}}</span></p>
                    <div>{{article.body}}</div>
            </div>
            <div class="col-xs-6 col-md-4">
                    <h2>广告</h2>
                    <p>跟老齐学 www.itdiffer.com</p>
                    <!-- <img width="200px" src="http://www.mrwallpaper.com/wallpapers/Fluffy-Cat.jpg">-->
                    <img width="200px" src="https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/topnav/baiduyun@2x-e0be79e69e.png">
            </div>
    </div>
    {% endblock %}

    3.编辑 blog/urls.py

    from django.conf.urls import url
    from . import views
    
    app_name="blog"
    urlpatterns = [
        url(r'^$',views.blog_title,name="blog_title"),
        url(r'(?P<article_id>d)/$',views.blog_article, name="blog_detail"),
    ]

    4.访问浏览器  点击blog title 马克思主义

    效果如下:

    PS: 因为我用的是docker环境,我把容器内的 8000端口映射到宿主机的8800端口了,所以看起来 有点不一样

  • 相关阅读:
    02-css的选择器学习.html
    01-css-css的声明.html
    10-描点学习
    09-HTML-form标签学习.html
    08-HTML-框架标签学习.html
    07-HTML-内嵌标签学习.html
    06-HTML-表格标签学习.html
    05-HTML-超链接标签.html
    04-HTML-图片标签学习.html
    03-HTML-body标签(列表标签).html
  • 原文地址:https://www.cnblogs.com/yaoyuanchun/p/13968543.html
Copyright © 2020-2023  润新知