1.打开终端,进入到django项目,创建APP应用:python manage.py startapp news
2.在settings.py中进行注册
3.在news下新建views.py,和urls.py。
views.py:
from django.shortcuts import render # Create your views here. from django.http import HttpResponse def index(request): return HttpResponse("hello world")
urls.py:
from django.contrib import admin from django.urls import path from . import views urlpatterns = [ path('',views.index), ]
4.在myweb中的urls.py
from django.contrib import admin from django.urls import path,include from news import urls urlpatterns = [ path('admin/', admin.site.urls), path('', include(urls)), ]
5.启动服务
python manage.py runserver