Python Django路径配置实现过程解析
作者:南风丶轻语 时间:2023-11-13 20:50:02
假设访问的views.py如下
1.使用url配置默认页
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from HelloWorld import views
urlpatterns = [
path('admin/', admin.site.urls),
url('^$', views.hello),
]
这样可以访问http://127.0.0.1:8090/
2.使用path配置默认页
from django.contrib import admin
from django.urls import path
from HelloWorld import views
urlpatterns = [
path('admin/', admin.site.urls),
# url('^$', views.hello),
path('', views.hello),
]
这样也可以访问http://127.0.0.1:8090/
3.使用path配置hello页
from django.contrib import admin
from django.urls import path
from HelloWorld import views
urlpatterns = [
path('admin/', admin.site.urls),
# url('^$', views.hello),
# path('', views.hello),
path('hello/', views.hello),
]
这样可以访问http://127.0.0.1:8090/hello/
4.使用url和正则
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from HelloWorld import views
urlpatterns = [
path('admin/', admin.site.urls),
# url('^$', views.hello),
# path('', views.hello),
# path('hello/', views.hello),
url('^hello', views.hello),
]
可以访问http://127.0.0.1:8090/hello+任意字符
5.如果有多个app,还可以使用include
from django.contrib import admin
from django.urls import path, include
from CRUD import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.login_html),
path('login.html/', views.login_html),
path('index.html/', views.index_html),
path('debug.html/', views.debug_html),
path('debug/', views.debug),
path('login/', views.login),
path('one/', include('Model.urls')),
path('two/', include('Model2.urls')),
path('three/', include('Model3.urls')),
path('four/', include('Model4.urls')),
]
来源:https://www.cnblogs.com/rainbow-tan/p/13919782.html
标签:Python,Django,路径,配置
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一文带你学会MySQL的select语句
2024-01-16 01:07:30
![](https://img.aspxhome.com/file/2023/1/69261_0s.jpg)
SQL Server 2008及更高版本数据库恢复方法之日志尾部备份
2024-01-25 09:22:37
![](https://img.aspxhome.com/file/2023/1/129311_0s.png)
pyqt5 QProgressBar清空进度条的实例
2022-11-28 03:04:08
DjangoRestFramework 使用 simpleJWT 登陆认证完整记录
2021-03-29 18:34:12
![](https://img.aspxhome.com/file/2023/1/76001_0s.png)
python 读取串口数据的示例
2021-08-30 11:10:26
浅谈python已知元素,获取元素索引(numpy,pandas)
2023-08-04 16:01:00
记录无法安装mysql-Invalid GPG Key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql的解决办法
2024-01-13 00:24:22
python中virtualenvwrapper安装与使用
2022-07-28 03:21:52
python3判断url链接是否为404的方法
2021-11-12 15:17:54
200行代码实现blockchain 区块链实例详解
2024-05-02 16:28:46
![](https://img.aspxhome.com/file/2023/3/130483_0s.png)
Python万物皆对象理解及源码学习
2023-05-14 13:34:02
![](https://img.aspxhome.com/file/2023/4/134734_0s.png)
利用webstrom调试Vue.js单页面程序的方法教程
2023-06-27 01:21:25
![](https://img.aspxhome.com/file/2023/5/55905_0s.jpg)
mysql使用LOAD语句批量录入数据方法
2010-03-09 16:31:00
用ASP和SQL实现基于Web日历源码
2010-04-24 15:52:00
XML卷之实战锦囊(2):动态查询
2008-09-05 17:20:00
Pytorch框架实现mnist手写库识别(与tensorflow对比)
2022-07-30 00:41:42
![](https://img.aspxhome.com/file/2023/7/85297_0s.jpg)
oracle的nvl函数的使用介绍
2023-07-19 14:42:20
SQL Server中通用数据库角色权限的处理详解
2024-01-18 17:24:27
![](https://img.aspxhome.com/file/2023/9/113529_0s.png)
Zend Framework教程之资源(Resources)用法实例详解
2023-11-06 02:49:50
Python垃圾回收机制三种实现方法
2023-02-22 00:24:42
![](https://img.aspxhome.com/file/2023/2/82832_0s.jpg)