zoukankan      html  css  js  c++  java
  • 【Django】url(路由系统)

    1、单一路由对应

      url(r'^index/',views.index),

    2.基于正则的路由

      url(r'^index/(d*)', views.index),

      url(r'^manage/(?P<name>w*)/(?P<id>d*)', views.manage),
    3.默认值
    urlpatterns = [
    
        url(r'^index/',views.index,{'name':'root'}),
    
    ]
    project/urls.py
    from django.shortcuts import render,HttpResponse,redirect
    from django.urls import reverse
    
    # Create your views here.
    def index(request,name):
        print(name)
        return HttpResponse(name)
    app01/views.py

    4.路由分发

    from django.contrib import admin
    from django.conf.urls import url,include
    
    urlpatterns = [
        url('^admin/', admin.site.urls),
        url(r'^app01/',include("app01.urls")),
        url(r'^app02/',include("app02.urls")),
    ]
    project/urls.py
    from django.contrib import admin
    from django.conf.urls import url
    from app01 import views
    
    urlpatterns = [
        url('^index/', views.index),
        url('^user_info/', views.user_info),
        url('^userdetail-(?P<nid>d+)/', views.user_detail),
        url('^home/', views.Home.as_view()),
    ]
    app01/urls.py
    from django.contrib import admin
    from app02 import views
    from django.conf.urls import url
    
    urlpatterns = [
        url('^login/', views.login),
    ]
    app02/urls.py
    5.命名空间
    from django.contrib import admin
    from django.conf.urls import url,include
    from app01 import views
    
    urlpatterns = [
        url(r'^app01/', include('app01.urls', namespace='author')),
    ]
    project/urls.py
    from django.contrib import admin
    from django.conf.urls import url,include
    from app01 import views
    
    app_name = 'app01'
    
    urlpatterns = [
        url(r'^index/',views.index,name='daly'),
    ]
    app01/urls.py
    from django.shortcuts import render,HttpResponse,redirect
    from django.urls import reverse
    
    # Create your views here.
    def index(request):
        v = reverse('author:daly')
        print(v)
        return HttpResponse('OK')
    app01/views.py

  • 相关阅读:
    java8关于list的操作
    jdk8的.toMap()
    Mybatis中报错org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题解决
    springboot集成bootstrap遇到的问题
    java文件下载
    idea中mybatis自动生成代码方式
    文件读写操作inputStream转为byte[] , 将InputStream写入本地文件
    Polar transformer networks
    Fine-Grained Person Re-identification
    Person Re-identification by Contour Sketch under Moderate Clothing Change
  • 原文地址:https://www.cnblogs.com/dalyday/p/8971232.html
Copyright © 2011-2022 走看看