Skip to main content
 首页 » 编程设计

python之通过 URL 访问的 Django 错误端点

2025年05月04日24zengkefu


我的 Django 应用程序中有 2 个 URL 模式:

url_patterns = [ 
    url(r'test/read/all/', TestViews.test_read_all), 
    url(r'test/read/all/custom/', TestViews.test_read_all_custom) 
] 

我的问题是:当我尝试访问 test/read/all/custom/ URL 时,请求被定向到 test/read/all/ URL(TestViews.test_read_all 被触发而不是 TestViews.test_read_all_custom)

编辑

两个端点方法具有相同的 api View 装饰器 (@api_view(["GET"]))

请您参考如下方法:

您必须在 url 末尾添加字符串结尾符号 '$':

url(r'^test/read/all/$', TestViews.test_read_all),