【Django】在vscode中新建Django应用并新增路由
文章目录
打开一个终端
输入新建app命令
python manage.py startapp antapp
在app下的views.py内写一个视图
from django.http import HttpResponse
# Create your views here.
def hello(request):
return HttpResponse("this is hello/")
app路由引入该视图
from django.contrib import admin
from django.urls import path
from antapp import views
urlpatterns = [
path("hello/", views.hello),
]
项目路由引入app路由
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配置类)
"antapp.apps.AntappConfig",
运行项目
原文地址:https://blog.csdn.net/xzzteach/article/details/140646607
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!