gpt4 book ai didi

带有 2 个参数的 django url 模式

转载 作者:行者123 更新时间:2023-12-03 15:19:41 28 4
gpt4 key购买 nike

这很简单,很明显,但我做对了:

我在 urls.py 中声明了以下 View 函数

 (r'^v1/(\d+)$', r'custom1.views.v1'),

最初我将一个参数传递给 View 函数 v1。
我想修改它以传递2个参数。如何在 urls.py 中声明条目以采用两个参数?

最佳答案

假设您希望 URL 看起来像 v1/17/18并获得两个参数1718 ,您可以将模式声明为:

(r'^v1/(\d+)/(\d+)$', r'custom1.views.v1'),

确保 v1除了请求对象之外,还接受两个参数:
def v1 ( request, a, b ):
# for URL 'v1/17/18', a == '17' and b == '18'.
pass

first exampledocumentation about the URL dispatcher包含几个模式,最后一个需要 2 和 3 个参数。

关于带有 2 个参数的 django url 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6587712/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com