【Django】在vscode中新建Django应用并新增路由

文章目录

打开一个终端

输入新建app命令

python 复制代码
python manage.py startapp antapp

在app下的views.py内写一个视图

python 复制代码
from django.http import HttpResponse

# Create your views here.
def hello(request):
    return HttpResponse("this is hello/")

app路由引入该视图

python 复制代码
from django.contrib import admin
from django.urls import path
from antapp import views

urlpatterns = [
    path("hello/", views.hello),
]

项目路由引入app路由

python 复制代码
from django.contrib import admin
from django.urls import path,include

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("antapp.urls")),
]

项目(settings.py)引入app(AntappConfig配置类)

python 复制代码
 "antapp.apps.AntappConfig",

运行项目

相关推荐
龙腾AI白云3 小时前
AI智能体搭建(3)深度搜索智能体如何搭建与设计 Agent#智能体搭建#多智能体#VLA#大模型
python·django·virtualenv·scikit-learn·tornado
践行见远6 小时前
django之认证与权限
python·django
言之。7 小时前
Django原子请求
数据库·django·sqlite
m0_748245928 小时前
SQLite 数据类型概述
java·数据库·sqlite
hqwest8 小时前
码上通QT实战27--系统设置02-加载用户列表
开发语言·qt·sqlite·qtablewidget
@zulnger9 小时前
Django 框架
数据库·django·sqlite
电子_咸鱼9 小时前
Linux IPC 实战:管道与共享内存的使用场景 + 底层原理全剖析
linux·运维·服务器·开发语言·网络·vscode·qt
CQ_YM10 小时前
SQLite3 数据库与网页html
c语言·数据库·sqlite·html
开开心心_Every10 小时前
一键隐藏窗口到系统托盘:支持任意软件摸鱼
服务器·前端·python·学习·edge·django·powerpoint