作者: zifanwang 发布于2020-06-14
首先修改settings.py的末尾:
FILE_CHARSET='gb18030'
DEFAULT_CHARSET='utf-8'
LANGUAGE_CODE = 'zh-Hans'
TIME_ZONE = 'Asia/Shanghai'
...
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
在settings.py添加FILE_CHARSET='gb18030'和DEFAULT_CHARSET='utf-8'以后网站就可以添加中文了。 下面修改shou/shou.html:
{% extends "basee.html" %}
{% block title %}
我的小站-首页
{% endblock title %}
{% block content %}
<style type="text/css">
.cardbox {
width: 100%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
text-align: center;
text-align: center;
float: left;
margin-right: 10px;
padding: 2px;
padding-top: 2px;
background-color: #FFFFFF;
}
.headerbox {
color: #fff;
padding: 1px;
font-size: 16px;
height: 100%;
}
.bodybox {
padding: 8px;
}
.bodybox p {
margin-left: 5px;
}
</style>
<body background="/img/ice_range.jpg"
style=" background-repeat:no-repeat ;background-size:100% 100%;background-attachment: fixed;">
<br>
<center>
<h1>我的个人网站</h1>
<p>——欢迎来到我的小站</p>
<hr>
</center>
<div class="container">
{% for article in articles %}
<div class="col-12 mb-12">
<div class="row mt-2 container">
<div class="cardbox">
<div class="headerbox" style="background-color: #99ffcc;">
<h5>
<h5><a title="article" style="cursor: pointer; color:black">{{ article.title }}</a></h5>
</h5>
<a href="{% url 'article:article_detail' article.id %}" class="btn btn-primary">read</a>
<span>
<span style="color: green">
{{ article.created|date:"Y-m-d" }}
</span>
<small class="col align-self-end" style="color: gray;">
views: {{ article.total_views }}
</small>
</span>
<h6></h6>
</div>
</div>
<div class="cardbox">
<div class="bodybox"><p>{{ article.body|cut:"#"|cut:"```"|striptags|slice:'300' }}</p>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
再创建templates/404.html:
{% extends "base.html" %}
{% load static %}
{% block title %}
404 - 页面没找到
{% endblock title %}
{% block content %}
<div class="container">
<center>
<h2>404 - 页面没找到</h2>
<p>你想查看的页面已被转移或删除了</p>
<h3><img src="/img/my_ico.jpg" width="70" height="70" /></h3>
</center>
</div>
{% endblock content %}
注意:要等到上线的时候404.html才会起作用。 然后可以再自己优化一下,截一下最后做出来的样子:
(还没结束,还有下一章。)