【Django】第一行代码

生成helloworld工程

django-admin startproject helloworld

工程文件介绍

在这里插入图片描述

  1. manage.py
    项目管理脚本
  2. helloworld
    项目路径
  3. helloworld/init.py
    指示改文件夹是个python包
  4. helloworld/asgi.py
    ASGI兼容的web server入口
  5. helloworld/settings.py
    django配置文件
  6. helloworld/urls.py
    web 的 path目录
  7. 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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_34954047/article/details/124291581