生成helloworld工程
django-admin startproject helloworld
工程文件介绍
- manage.py
项目管理脚本 - helloworld
项目路径 - helloworld/init.py
指示改文件夹是个python包 - helloworld/asgi.py
ASGI兼容的web server入口 - helloworld/settings.py
django配置文件 - helloworld/urls.py
web 的 path目录 - helloworld/wsgi.py
WSGI兼容的web server入口
ASGI与WSGI是什么
https://blog.csdn.net/huayunhualuo/article/details/106007545
coding
编写视图
vim helloworld/view.py
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world ! ")
增加路径
vim helloworld/urls.py
如上图添加这两行代码
from . import view
path('hello/', view.hello),
其目的是链接访问路径hello到刚刚编写的view.py的hello函数
运行
python3 mange.py runserver