django-admin startproject

目录

1. django-admin startproject

2.python manage.py startapp

3.创建view视图以及指定url

4.添加web url 到webproject 的urls

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

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值