麻瓜编程·python实战·4-1作业:搭建简易博客
2016-08-23 本文已影响0人
bbjoe
我的结果
- 我用的pycharm 2016.2.1 pro,新建项目,选择Django,点击齿轮按钮,创建虚拟环境,命名这个环境(最好以venv结尾表示是虚拟环境)




-
先设置app中的view.py,表示有请求了之后该怎么办。
设置index.py引导到index.html
-
再设置url,把url添加进去,当请求 xxx/index/ 的时候就会指向views.py的index函数。
设置项目中的url.py,添加`url`
-
index函数返回的index.html现在开始构建,首先在templates里面新建index.html。
在templates中新建html,命名为index.html,把博客的html复制进去
-
以下是关于css的套路:static文件夹
在项目的目录中创建文件夹“static”,把博客的css和image放进去

因为index.html中的各种地址引用,jpg啊,css啊都是从static目录来的,所以一是要核对以下路径,二是在templates中有规定的格式,即:
{% static '...' %}

-
在虚拟项目中的setting.py中,末尾添上static的地址,写法是套路(实际上我并没有很理解清楚)
在setting中添加static的路径
7.最后就是在pycharm的teminal中输入:python3 manage.py runservice
,浏览器请求地址:http://127.0.0.1:8000/index/