改變外觀
(一)新增templates目錄
加入兩個模版檔案
(1)base.html檔案
<html>
<style type="text/css" >
body {color: #efd; background: #435; padding: 0 5em;margin: 0}
h1 {padding: 2em 1em; background: #675}
h2 {color: #bf8; border-top: 1px dotted #fff; margin-top: 2em}
p {margin: 1em 0}
</style>
<head>
<title><!-- Insert your title here --></title>
</head>
<body>
<h1>mysite.example.com</h1>
{% block content %}
{% endblock %}
</body>
</html>
(2)archive.html檔案
{% extends "base.html" %}
{% block content %}
{% for post in posts %}
<h2>{{ post.title }}</h2>
<p>{{ post.timestamp }}</p>
<p>{{ post.body }}</p>
{% endfor %}
{% endblock %}
其中extends "base.html"表示将上面建立的base.html檔案引入到本檔案中
(二) 按照timestamp降序排列
在models.py中加入
class Meta:
ordering=('-timestamp',)
(三)啟動伺服器并測試
python -Wall manage.py runserver
-Wall參數用于調試