我有一个字典列表如下:
listDict = [{'product':'sandwich','price':'5200'}, {'product':'hamburger','price':'3000'}]
Run Code Online (Sandbox Code Playgroud)
迭代我做的元素:
{%for element in listDict%}
{% for key,value in element.items %}
<input type="checkbox" name = "bar" value = "{{ value }}">{{ value }}<br>
{% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
正如预期的那样,这将打印:
sandwich
5200
hamburger
3000
Run Code Online (Sandbox Code Playgroud)
但我怎么能连接这些值才能打印出这样的东西:
sandwich - 5200
hamburger - 3000
Run Code Online (Sandbox Code Playgroud)
我不能做以下的事情:
for element in listDict:
element['product']+" - "+element['price']
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我有一个关于python函数和参数的基本问题
鉴于此功能:
def findArticleWithAttr(tableattrib, user_url_input):
articles = Something.objects.filter(tableattrib=user_url_input)
Run Code Online (Sandbox Code Playgroud)
我用以下函数调用该函数:
findArticleWithAttr(attribute1, userinput1)
Run Code Online (Sandbox Code Playgroud)
tableattrib不是由findArticleWithAttr属性1设置的,只是接受后者(userinput1)参数并替换它.
我怎样才能让python在等式中设置两个参数?