2017-09-26 3 views
-1

大きな内容のドリルダウンボタンは表示されませんでした。 私はボタンをドリルダウンボタンのcontent.But今だけの小さなコンテンツをドリルダウンviews.pyが大きなドリルダウンボタンを表示していません

from collections import OrderedDict 
from django.shortcuts import render 
import json 
from django.http import JsonResponse 

def index(request): 
    with open('./data/company_demand.json', 'r') as f: 
     json_data = json.loads(f.read(), object_pairs_hook=OrderedDict) 

     preprocessed = [] 
     counter = 0 
     for key in ["type1", "type2", "type3", "type4"]: 
      values = [(i + counter, value) for i, value in enumerate(json_data[key].values())] 
      preprocessed.append((key, values)) 
      counter = len(json_data[key]) 
    return render(request, 'index.html', {'json_data': json_data}, {'preprocessed': preprocessed}) 

指標である

{'items': {'---': '---', 
      ‘A’: ‘a’, 
      ‘B’: ‘b’, 
      ‘C: ‘c’, 
      ‘D’: ‘d’}, 
'type1': 
     { 
     "---":"---", 
     "a1":"a1", 
     "a2":"a2", 
     "a3":"a3", 
     "a4":"a4" 
    }, 
    'type2': 
     { 
     "---":"---", 
     "b1":"b1", 
     "b2":"b2", 
     "b3":"b3", 
     "b4":"b4" 
    }, 

    'type3': 
     { 
     "---":"---", 
     "c1":"c1", 
     "c2":"c2", 
    }, 

    'type4': 
     { 
     "---":"---", 
     "d1":"d1", 
     "d2":"d2", 
     "d3":"d3" 
    }, 
} 

ようshown.jsonがあるJSONファイルとなるファイルの内容を読み込みます.htmlのは

<select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;"> 
    {% for i in json_data.items.values %} 
      <option>{{ i }}</option> 
    {% endfor %} 
    </select> 
{% for key, values in preprocessed %} 
    <select name="type" id="{{ key }}"> 
    {% for counter, value in values %} 
     <option value="{{ counter }}">{{ value }}-{{counter}}</option> 
    {% endfor %} 
    </select> 
{% endfor %} 

しかし今、この部分で

<select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;"> 
    {% for i in json_data.items.values %} 
      <option>{{ i }}</option> 
    {% endfor %} 
    </select> 

は表示されません。なぜこのようなエラーが発生しますか?これをどのように修正する必要がありますか?

答えて

0

json_dataとpreprocessedは、テンプレートに渡された同じ辞書に入れる必要があります。

return render(request, 'index.html', {'json_data': json_data, 'preprocessed': preprocessed}) 

変更

return render(request, 'index.html', {'json_data': json_data}, {'preprocessed': preprocessed}) 

関連する問題