码迷,mamicode.com
首页 > 其他好文 > 详细

6-视图

时间:2019-11-28 23:17:38      阅读:89      评论:0      收藏:0      [点我收藏+]

标签: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去处理

 

 

 

 

 

 

(未完待续,,,,,,,)

6-视图

标签:src   并集   div   view   hello   port   新建   html   应用   

原文地址:https://www.cnblogs.com/xymaxbf/p/11954240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!