Python 系列(23) django 二次路由

Posted on Posted in python

新建两个app

  1. python manage.py startapp blog
  2. python manage.py startapp monitor

mydjango/settings.py

  1. INSTALLED_APPS = [
  2.     'django.contrib.admin',
  3.     'django.contrib.auth',
  4.     'django.contrib.contenttypes',
  5.     'django.contrib.sessions',
  6.     'django.contrib.messages',
  7.     'django.contrib.staticfiles',
  8.     'app01',
  9.     'blog',
  10.     'monitor',
  11. ]

二级路由

mydjango/urls.py

  1. from django.conf.urls import url, include # 导入include
  2. from django.contrib import admin
  3. from app01 import views
  4. import blog.views
  5. import monitor.views
  6. urlpatterns = [
  7.     url(r'^monitor/', include('monitor.urls')), # http://192.168.1.250:8000/monitor/index/
  8.     url(r'^blog/', include('blog.urls')), # 用include把子项包含进去
  9.     url(r'^admin/', admin.site.urls),
  10. ]

blog/urls.py

  1. from django.conf.urls import url, include
  2. from django.contrib import admin
  3. from . import views
  4. urlpatterns = [
  5.     url(r'^index/', views.index),
  6. ]

monitor/urls.py

  1. from django.conf.urls import url, include
  2. from django.contrib import admin
  3. from . import views
  4. urlpatterns = [
  5.     url(r'^index/', views.index),
  6. ]

blog/templates/blog_index.html

  1. <html lang="zh">
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. blog templates index page
  8. </body>
  9. </html>

monitor/templates/monitor_index.html

  1. <html lang="zh">
  2. <head>
  3. <meta charset="utf-8">
  4. <title>Title</title>
  5. </head>
  6. <body>
  7. monitory templates index page
  8. </body>
  9. </html>

Leave a Reply

Your email address will not be published. Required fields are marked *

five + thirteen =