【小白实战】利用django2.0,搭建属于自己的博客(三)


发布时间:2019-02-15 13:08    作者: Uncle Hui   已过去:1 年,7 月   阅读总量:1273 已被赞:2


【templates/blog/下新建第二个页面】

新建index.html ----复制这些代码进去:

{% extends 'blog/base.html' %}
{% load staticfiles %}
{% block welcome %}
<div class="blog-header">
<h1 class="blog-title">晖哥哥-Blog2019</h1>
<p class="lead blog-description">本博客基于Bootstrap搭建,纯练手项目。</p>
</div>
{% endblock %}
{% block post %}
<div class="blog-post">
                    <h2 class="blog-post-title">New feature</h2>
                    <p class="blog-post-meta">December 14, 2013 by <a href="#">Chris</a></p>

                    <p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean lacinia bibendum nulla sed consectetur. Etiam porta sem malesuada magna mollis euismod. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
                    <ul>
                      <li>Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</li>
                      <li>Donec id elit non mi porta gravida at eget metus.</li>
                      <li>Nulla vitae elit libero, a pharetra augue.</li>
                    </ul>
                    <p>Etiam porta <em>sem malesuada magna</em> mollis euismod. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur.</p>
                    <p>Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue.</p>
                  </div><!-- /.blog-post -->
{% endblock %}
{% block you %}
<div class="sidebar-module sidebar-module-inset">
                    <h4>About</h4>
                    <p>Etiam porta <em>sem malesuada magna</em> mollis euismod. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur.</p>
                  </div>
                  <div class="sidebar-module">
                    <h4>Archives</h4>
                    <ol class="list-unstyled">
                      <li><a href="#">March 2014</a></li>
                      <li><a href="#">February 2014</a></li>
                      <li><a href="#">January 2014</a></li>
                      <li><a href="#">December 2013</a></li>
                      <li><a href="#">November 2013</a></li>
                      <li><a href="#">October 2013</a></li>
                      <li><a href="#">September 2013</a></li>
                      <li><a href="#">August 2013</a></li>
                      <li><a href="#">July 2013</a></li>
                      <li><a href="#">June 2013</a></li>
                      <li><a href="#">May 2013</a></li>
                      <li><a href="#">April 2013</a></li>
                    </ol>
                  </div>
                  <div class="sidebar-module">
                    <h4>Elsewhere</h4>
                    <ol class="list-unstyled">
                      <li><a href="#">GitHub</a></li>
                      <li><a href="#">Twitter</a></li>
                      <li><a href="#">Facebook</a></li>
                    </ol>
                  </div>
            <footer class="blog-footer">
              <p>Blog template built for <a href="http://getbootstrap.com">Bootstrap</a> by <a href="https://twitter.com/mdo">@mdo</a>.</p>
              <p>
                <a href="#">Back to top</a>
              </p>
            </footer>
        {% endblock %}

 

代码简单说明:

{% extends 'blog/base.html' %}  继承这个父模板

{% block 。。。。 %}  中间写入这个页面的展示内容,就是在填空  {% endblock %}

【视图设置blog/views.py】

rom django.shortcuts import render

# Create your views here.

def index(request):
    return render(request,'blog/index.html')

【分路由设置】

在blog新建一个py文件,名字取名:urls.py,你也也可以取一个其他的,但这个直观!,在里面输入:

from django.urls import path
from .views import index

urlpatterns = [
    path('', index,name='index'),#引号里是空白,说明是首页路由,name是取得别名!
]

【总路由设置:blog2019下的urls.py下设置】

from django.contrib import admin
from django.urls import path,include
from blog import urls
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include(urls)),
    path('blog/', include(urls)),

【启动项目,看看效果】

​​​​​​效果不错,可以继续了!

看看项目树:

点赞

2




登陆后方可评论