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")),
    ]

  • 相关阅读:
    单调队列和单调栈
    二叉搜索树(BST)
    高斯消元和高斯约旦消元 Gauss(-Jordan) Elimination
    扩展欧几里德算法
    基数排序
    智力题研究
    快速排序和快速选择
    快读模板
    C#知识点
    C#字段属性设置
  • 原文地址:https://www.cnblogs.com/xiximayou/p/11738412.html
Copyright © 2011-2022 走看看