1.在路径XXXXX\mydjango\mydjango\mydjango下新建views.py(在浏览器中url请求后所展示的内容设置)
from django.http import HttpResponse def hello(request): return HttpResponse("Hello world ! ")
2.绑定url与视图函数,在路径XXXXX\mydjango\mydjango\mydjango下打开urls.py,先导入第一步创建的views,然后设置url地址
from django.urls import path from . import views urlpatterns = [ path('hello/', views.hello), ]
3.启动项目(上一篇中已讲过),浏览器中请求地址:127.0.0.1:8000/hello/
本文链接:http://task.lmcjl.com/news/15483.html