https://www.zerotheme.com/
下载主题模板
创建 base.html
首行加载static文件
{% load static %}
...
...
...
{% if title %}
<title>Django Blog - {{ title }}</title>
{% else %}
<title>Django Blog</title>
{% endif %}
</head>
修改所有link标签,添加
<link href="{% static 'css/clean-blog.min.css' %}" rel="stylesheet">
<header class="masthead" style="background-image: url('img/home-bg.jpg')">
改为
<header class="masthead" style="background-image: url('/static/img/home-bg.jpg')">
<script src="{% static 'js/clean-blog.min.js' %}"></script>
创建index.html 继承base.html
{% extends 'blog/base.html' %}
创建about.html
trydjango/blog/templates/blog/about.html内容如下
{% extends "blog/base.html" %}
{% block content %}
<h1>About Page</h1>
{% endblock content %}
添加views视图
trydjango/blog/views.py
...
...
...
def about(request):
return render(request, 'blog/about.html', {'title': 'About'})
添加url
trydjango/blog/urls.py
...
...
...
path('about/', views.about, name='blog-about'),
...
修改base.html链接
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
创建static文件夹,拷贝主题中的文件夹
trydjango
|-- blog
| |--static
| |--css
| |--img
| |--js
| |--mail
| |--scss
| `--vendor
|
| |--templates
| |--blog
| |--about.html
| |--contact.html
| |--index.html
| |--post.html
| `--base.html
内容分页
from django.shortcuts import render
from blog.models import Post
from django.core.paginator import Paginator
# Create your views here.
def hello(request):
context = {}
context['hello'] = 'Hello World!'
return render(request, 'blog/hello.html', context)
def listing(request):
post_list = Post.objects.all()
paginator = Paginator(post_list, 2)
page = request.GET.get('page')
posts = paginator.get_page(page)
return render(request, 'blog/index.html', {'posts': posts})
trydjango/blog/templates/blog/index.html
未美化
下载主题模板
创建 base.html
首行加载static文件
{% load static %}
...
...
...
{% if title %}
<title>Django Blog - {{ title }}</title>
{% else %}
<title>Django Blog</title>
{% endif %}
</head>
修改所有link标签,添加
<link href="{% static 'css/clean-blog.min.css' %}" rel="stylesheet">
<header class="masthead" style="background-image: url('img/home-bg.jpg')">
改为
<header class="masthead" style="background-image: url('/static/img/home-bg.jpg')">
<script src="{% static 'js/clean-blog.min.js' %}"></script>
创建index.html 继承base.html
{% extends 'blog/base.html' %}
创建about.html
trydjango/blog/templates/blog/about.html内容如下
{% extends "blog/base.html" %}
{% block content %}
<h1>About Page</h1>
{% endblock content %}
添加views视图
trydjango/blog/views.py
...
...
...
def about(request):
return render(request, 'blog/about.html', {'title': 'About'})
添加url
trydjango/blog/urls.py
...
...
...
path('about/', views.about, name='blog-about'),
...
修改base.html链接
<a class="nav-item nav-link" href="{% url 'blog-about' %}">About</a>
trydjango
|-- blog
| |--static
| |--css
| |--img
| |--js
| |--scss
| `--vendor
|
| |--templates
| |--blog
| |--about.html
| |--contact.html
| |--index.html
| |--post.html
| `--base.html
内容分页
from django.shortcuts import render
from blog.models import Post
from django.core.paginator import Paginator
# Create your views here.
def hello(request):
context = {}
context['hello'] = 'Hello World!'
return render(request, 'blog/hello.html', context)
def listing(request):
post_list = Post.objects.all()
paginator = Paginator(post_list, 2)
page = request.GET.get('page')
posts = paginator.get_page(page)
return render(request, 'blog/index.html', {'posts': posts})
trydjango/blog/templates/blog/index.html
未美化
评论
发表评论