首页 > 代码库 > Django 创建APP - 简单路由系统案例

Django 创建APP - 简单路由系统案例

架构图:

技术分享

 

setting.py:

技术分享
INSTALLED_APPS = [    ...    bootstrap,]
View Code

 

myapp -> myapp -> urls.py

技术分享
from django.conf.urls import url, includefrom django.contrib import adminurlpatterns = [    url(r^admin/, admin.site.urls),    url(r^bootstrap/, include(bootstrap.urls)),    ]
View Code

 

myapp -> bootstrap -> urls.py

技术分享
from django.conf.urls import urlfrom . import viewsurlpatterns = [    url(r^$, views.index, name=index),    url(r^helloworld/, views.helloworld, name=helloworld),    ]
View Code

 

myapp -> bootstrap -> views.py

技术分享
from django.shortcuts import render# Create your views here.from django.http import   HttpResponsedef helloworld(request):    return HttpResponse("Hello   world")def index(request):    return HttpResponse("Hello, world. You‘re at the polls index.")
View Code

 

截图一: index

技术分享

截图二: helloworld

技术分享

 

Django 创建APP - 简单路由系统案例