In my dhango project i create a function callable via url:
url(r'^pd/(?P<c_id>[\w\-]+)\/$', calc_q),
So my function need to manage at least 4 input
@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? Is possible pass all variables directly in url? Whitch is the best method?
So many thanks in advance
You can do that in the following manner :
urls.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"
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.