目录结构

polls/urls.py为新增文件。

Python Django 4.2.5教程:编写视图view_django

cat mysite/urls.py

from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('polls',include('polls.urls')),
]

cat polls/urls.py

from django.urls import path
from . import views

urlpatterns=[
    path('',views.index,name='index'),
]

cat polls/views.py

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def index(request):
    return HttpResponse("is index view")

links:
https://www.w3cschool.cn/django4/django4-qi9c3lyp.html