S
S
Sanya Hihi Haha2020-04-19 09:59:12
Django
Sanya Hihi Haha, 2020-04-19 09:59:12

How to output dict in template correctly?

Ku everyone, there is such a
mixin resMIxin.py

class ResourceMixin(object):
  def get_resource_info(self, uid, *args, **kwargs):
    #получаем кол-во всех ресурсов
    get_res = UserResource.objects.get(user_res_id=uid)
    
    stone_quant = get_res.user_stone
    tree_quant = get_res.user_tree
    steel_quant = get_res.user_steel

    # STONE
    stone_mine_info = UserStoneMiner.objects.get(user_stone_mine_id=uid) # get level
    #tree
    tree_mine_info = UserTreeMiner.objects.get(user_tree_mine_id=uid)
    #steel
    steel_mine_info = UserSteelMiner.objects.get(user_steel_mine_id=uid)

    resource_info = {'stone':{'quant:':stone_quant,'level':stone_mine_info.stone_mine_level},
             'tree':{'quant':tree_quant,'level':tree_mine_info.tree_mine_level},
             'steel':{'quant':steel_quant,'level':steel_mine_info.steel_mine_level}}


    return resource_info

views.py - call the method and get the dict
player_mine_resource = ResourceMixin.get_resource_info(self,uid)

What is my problem? - in the template, trying to display quant - I do not get the value, but level - shows

<div class='block' style='padding:7px;'>
<b style='color:#66CC33;'> Мои ресурсы: </b> <br>
<img src="{% static 'img/castle-resource/icon/stone.png' %}" style='width:24px;height:24px;'> {{ player_resource.stone.quant }}
&nbsp;<img src="{% static 'img/castle-resource/icon/tree.png' %}" style='width:24px;height:24px;'> {{ player_resource.tree.level }}
&nbsp;<img src="{% static 'img/castle-resource/icon/steel.png' %}" style='width:24px;height:24px;'> {{ res.steel }}
</div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question