简体   繁体   English

Django 将参数列表传递给 url

[英]Django pass to an url a list of parameters

In my dhango project i create a function callable via url:在我的 dhango 项目中,我创建了一个可通过 url 调用的函数:

url(r'^pd/(?P<c_id>[\w\-]+)\/$', calc_q),

So my function need to manage at least 4 input所以我的功能需要管理至少 4 个输入

@csrf_exempt
def calc_q(request, c_id):

    start_d = datetime.date(2021, 6, 28)
    end_d = datetime.date(2021, 6, 29)
    v_id = 17
    q_time ="15min"
    ...

How can i pass, for example a list or a dict from url to my function with my 4 variables inside?我如何将例如列表或字典从 url 传递给我的函数,其中包含我的 4 个变量? Is possible pass all variables directly in url?是否可以直接在 url 中传递所有变量? Whitch is the best method?哪种方法最好?

So many thanks in advance非常感谢提前

You can do that in the following manner :您可以通过以下方式做到这一点:

urls.py网址.py

url(r'^pd/(?P<c_id>[\w\-]+)\(?P<value>\d+)/$', calc_q)

then in your template然后在你的模板中

<a href="{% url 'name_url' value=0 %}">my link</a>

In your view:在您看来:

@csrf_exempt
def calc_q(request, c_id, value):

    start_d = datetime.date(2021, 6, 28)
    end_d = datetime.date(2021, 6, 29)
    v_id = 17
    q_time ="15min"
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM