Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of DJANGO-URL reverse parsing REVERSE

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report