django-URL实例命名空间十一

每生成一个地址,都是一个实例。使用实例命名空间,针对于一个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)">loose
 django.contrib import admin
 django.urls import path,include

urlpatterns =admin/,admin.site.urls),1)">book/book.urlsnamespace=)),1)">page/page

 

 

相关文章

注:所有源代码均实测运行过。所有源代码均已上传CSDN,请有...
继承APIView和ViewSetMixin;作用也与APIView基本类似,提供...
一、Django介绍Python下有许多款不同的 Web 框架。Django是重...
本文从nginx快速掌握到使用,gunicorn快速掌握到使用,实现小...
uniapp微信小程序订阅消息发送服务通知
Django终端打印SQL语句 1 Setting配置: 2 默认python 使用的...