我的结果
- 我用的pycharm 2016.2.1 pro,新建项目,选择Django,点击齿轮按钮,创建虚拟环境,命名这个环境(最好以venv结尾表示是虚拟环境)
![](https://img.haomeiwen.com/i2595866/7b0c115166614f7d.png)
![](https://img.haomeiwen.com/i2595866/be39d8ba62a9e534.png)
![](https://img.haomeiwen.com/i2595866/6b546db6908903f9.png)
![](https://img.haomeiwen.com/i2595866/edb143ff711896a9.png)
-
先设置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放进去
![](https://img.haomeiwen.com/i2595866/8062d40ae8156075.png)
因为index.html中的各种地址引用,jpg啊,css啊都是从static目录来的,所以一是要核对以下路径,二是在templates中有规定的格式,即:
{% static '...' %}
![](https://img.haomeiwen.com/i2595866/130fb18cf43fef50.png)
-
在虚拟项目中的setting.py中,末尾添上static的地址,写法是套路(实际上我并没有很理解清楚)
在setting中添加static的路径
7.最后就是在pycharm的teminal中输入:python3 manage.py runservice
,浏览器请求地址:http://127.0.0.1:8000/index/
网友评论