每生成一个地址,都是一个实例。使用实例命名空间,针对于一个app而言。
book/views.py
from django.http import HttpResponse django.shortcuts import render,redirect,reverse 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,b200})) def error(request,a,b): sum=a+b <h1>path:{}</h1>".format(request.path))
book/urls.py
django.urls import path . import views app_name =book urlpatterns = [ path('',views.index,name=index'),path(error/<int:a>/<int:b>',views.error,1)">loosedjango.contrib import admin django.urls import path,include urlpatterns =admin/,admin.site.urls),1)">book/book.urlsnamespace=)),1)">page/page
原文链接:/django/991018.html