Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of DJANGO-URL reverse parsing REVERSE

Shulou Source: shulou.com Published: 2022-06-03 19:16:57 10月26日 Update

This article mainly introduces the DJANGO-URL reverse parsing REVERSE example analysis, the article introduces in great detail, has a certain reference value, interested friends must read it!

Resolve paths with parameters in path.

Reverse (viewname,urlconf=None,args=None,Kwargs=None,current_app=None)

Book/views.py

From django.http import HttpResponsefrom django.shortcuts import render,redirect,reverse# Create your views here.def index (request): username = request.GET.get ("username") if username is not None: return HttpResponse ("welcome!") Else: return redirect (reverse ('loose',kwargs= {' afrol 100)) def error (request,a,b): sum=a+b return HttpResponse ("sum: {}" .format (sum))

Book/urls.py

From django.urls import pathfrom. Import viewsurlpatterns = [path (', views.index,name='index'), path ('error//', views.error,name='loose'),]

General process: after starting the server, the index function in views will be called. Since there is no username parameter, it will be redirected to loose (the namespace of views.error), that is, the error function will be called. At this time, there are two parameters, Amemb, which can only be passed through reverse.

The above is all the contents of the article "sample Analysis of DJANGO-URL reverse parsing REVERSE". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Parameters examples analysis content functions articles two values interests guys partners more servers knowledge space industry information information channels paths processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple vpn Microsoft MariaDB