带有2个参数的Django URL模式 [英] django url patterns with 2 parameters

查看:82
本文介绍了带有2个参数的Django URL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这简单明了,但我做不到:

This is simple and obvious but I can't get it right:

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

I have the following view function declared in urls.py

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

最初我是将单个参数传递给视图函数v1。
我想修改它以传递2个参数。我该如何声明urls.py中的条目采用两个参数?

originally I was passing a single parameter to the view function v1. I want to modify it to pass 2 parameters. How do I declare the entry in urls.py to take two parameters?

推荐答案

我相信正则表达式中的每个组都以一个参数(可以根据需要命名):

I believe each group in the regex is passed as a parameter (and you can name them if you want):

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

查看示例网址: https://docs.djangoproject.com/en/dev/topics/ http / urls / 。您也可以命名组。

Check out the examples at: https://docs.djangoproject.com/en/dev/topics/http/urls/. You can also name your groups.

这篇关于带有2个参数的Django URL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆