zoukankan      html  css  js  c++  java
  • django-URL实例命名空间(十一)

    每生成一个地址,都是一个实例。使用实例命名空间,针对于一个app而言。

    book/views.py

    from django.http import HttpResponse
    from django.shortcuts import render,redirect,reverse
    from django.urls import resolve
    
    # Create your views here.
    def index(request):
        username = request.GET.get("username")
        if username is not None:
            return HttpResponse("welcome!")
        else:
            path=request.path
            current_namespace=resolve(path).namespace
            return redirect(reverse('{}:loose'.format(current_namespace),kwargs={'a':100,'b':200}))
    
    def error(request,a,b):
        sum=a+b
        return HttpResponse("<h1>path:{}</h1>".format(request.path))

    book/urls.py

    from django.urls import path
    from . import views
    app_name ="book"
    urlpatterns = [
        path('', views.index,name='index'),
        path('error/<int:a>/<int:b>', views.error,name='loose'),
    ]

    主urls.py

    from django.contrib import admin
    from django.urls import path,include
    
    urlpatterns = [
        path('admin/', admin.site.urls),
        path('book/',include('book.urls',namespace="book")),
        path('page/',include('book.urls',namespace="page")),
    ]

  • 相关阅读:
    Linux系统类别
    ST-GCN基于skeleton的动作识别
    (gcc/g++)/clang/cl编译器
    羽毛球经典教材范例
    opencv批量读取图片
    十六、mysql 变量
    十五、mysql 存储过程
    十四、mysql 视图
    十三、mysql TCL语言
    十二、mysql 标识列
  • 原文地址:https://www.cnblogs.com/xiximayou/p/11738412.html
Copyright © 2011-2022 走看看