一、创建应用
![](https://img.haomeiwen.com/i14564474/c1b5bbc277ec4f8a.png)
e:\project\myblog>python manage.py startapp blog
在 \myblog\settings.py中添加应用名:
![](https://img.haomeiwen.com/i14564474/0df84960222bbcf0.png)
二、创建第一个页面(响应)
1、在urls中配置URL:
import blog.viewsas bv
path('index/', bv.index)
![](https://img.haomeiwen.com/i14564474/d80cb8d1f9facacd.png)
2.在blog/views.py 中添加:
from django.httpimport HttpResponse#引入HttpResponse 类
def index(request):
return HttpResponse("hello,world!");
![](https://img.haomeiwen.com/i14564474/222dd95133910a74.png)
3. 启动服务,在浏览器中打开 :localhost:8000/index/,第一个页面运行成功。
![](https://img.haomeiwen.com/i14564474/18613b007dcc653f.png)
![](https://img.haomeiwen.com/i14564474/160cd8c2e5d197bf.png)
![](https://img.haomeiwen.com/i14564474/d9cd4fda3857a70b.png)
![](https://img.haomeiwen.com/i14564474/62bd49ebe3b2d931.png)
很简单的一个页面,但是从对python 和 django 一无所知,到一步步搭建环境,建立应用,说难不难,说容易也不算容易。
网友评论