编写polls/views.py文件:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello Django");
配置url映射:在polls下新建,urls.py,并编辑/urls.py
from django.urls import path
from . import views
urlpatterns=[
path('',views.index, name='index'),
]
配置根目录url:novelWeb/urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns=[
path=('polls',include('polls.urls')),
path=('admin/',admin.stie.urls)
]
函数说明:
path():
最后运行:http://127.0.0.1:8000/polls/
python manage.py runserver