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

How to solve the problem of settings routing configuration in python

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how to solve the problem of settings routing configuration in python. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Writing the search for the view function directly to the primary route is not the best way, because our project will have a lot of routing configuration items. If it is all piled up in this main routing file, it must be very bloated, messy and difficult to maintain.

1. You can add a urls.py (child route) to each corresponding sub-application, and set the routing configuration of the view in it to access a route.

# my_project/apps/my_app/urls.pyfrom django.urls import pathfrom apps.my_app import views urlpatterns = [path ('', views.index)]

At present, although the routing file under the sub-application has been configured, the result of the corresponding view can not be seen during the access.

This is because ur's default search dynamic hierarchy is: primary route-> child route, layer-by-layer search, but we do not distribute a child route in the primary route, so we cannot access it.

2. Configure the master route to let the master route find the route under the sub-application.

# my_project/urls.pyfrom django.contrib import adminfrom django.urls import path, include # reference other url confsurlpatterns through the include () function = [path ('admin/', admin.site.urls), path (', include ('apps.my_app.urls')), # apps.my_app.urls equals apps/my_app/urls.py] Thank you for reading! This is the end of the article on "how to solve the problem of settings routing configuration in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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