小编use*_*222的帖子

字典的顺序每次都有所不同

尽管使用OrderedDict,每次都会改变字典的顺序.我在views.py中写道

from collections import OrderedDict

from django.shortcuts import render
import json

def index(request):
    with open('./data/data.json', 'r') as f:
        json_dict = json.loads(f.read())
        json_data = OrderedDict()
        json_data = json_dict
    return render(request, 'index.html', {'json_data': json_data})
Run Code Online (Sandbox Code Playgroud)

我在index.html中写道

<html>
?<head>
?<script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.8.2/chosen.jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"></script>
?<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css">
?</head>
?<body>
    <select id="mainDD" data-placeholder="Choose" class="chzn-select" style="width:600px;">
    {% for i in json_data.items.values %}
            <option>{{ i }}</option>
    {% endfor %}
    </select>
    <select name="type" id="type1">
    {% for j in json_data.type1.values %}
            <option>{{ j }}</option>
    {% endfor …
Run Code Online (Sandbox Code Playgroud)

python django dictionary

0
推荐指数
1
解决办法
54
查看次数

标签 统计

dictionary ×1

django ×1

python ×1