目录
5.启动项目python manage.py runserver
6.访问路径 http://127.0.0.1:8000/webview
1. django-admin startproject
(venv) (base) MacBook-Air webproject % django-admin startproject webproject
2.python manage.py startapp
(venv) (base) MacBook-Air webproject % python manage.py startapp webs
3.创建view视图以及指定url
3.1 创建视图 webs -> views代码块
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def webview(request):
return HttpResponse("welcome to web first page......")
3.2 创建urls.py
create urls.py under webs代码块
from django.urls import path
from . import views
urlpatterns = [
path('', views.webview),
]
3.3 项目代码结构图
4.添加web url 到webproject 的urls
4.1 代码块
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("webview/", include('webs.urls'))
]
4.2 项目代码结构图
5.启动项目python manage.py runserver
(venv) (base) MacBook-Air webproject % python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
April 05, 2023 - 09:41:57
Django version 4.2, using settings 'webproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
6.访问路径 http://127.0.0.1:8000/webview