标签:src 并集 div view hello port 新建 html 应用
view.py
from django.shortcuts import render from django.http import HttpResponse # Create your views here. def first_view(request): html=‘<p>Hello World!</p>‘ return HttpResponse(html)
urls.py
from django.contrib import admin from django.urls import path from firstApp import views urlpatterns = [ path(‘admin/‘, admin.site.urls), path(‘view/hello/‘,views.first_view) ]
为每一个应用单独定制一个urls.py,并集中通过include汇总到项目中的urls.py中
为应用新建一个urls.py
from django.urls import path from firstApp import views urlpatterns = [ path(‘hello/‘,views.first_view), ]
项目总urls.py
from django.contrib import admin from django.urls import path, include urlpatterns = [ path(‘admin/‘, admin.site.urls), path(‘firstapp/‘,include(‘firstApp.urls‘)) ]
这样,以firstapp开头的请求都会转移给firstapp应用的urls.py去处理
(未完待续,,,,,,,)
标签:src 并集 div view hello port 新建 html 应用
原文地址:https://www.cnblogs.com/xymaxbf/p/11954240.html