模板问题中的JSON对象上的Forloop

时间:2019-04-03 10:34:27

标签: django python-3.x

我想在Web应用程序上呈现熊猫DataFrame的每一行,因此我将其转换为json对象,但是我的查询未显示在我的网页上。我不懂为什么。 你能帮我吗?

view.py

def typeDetail(request,id,rt_id):

    normal_price=request.POST.get('normal_price')
    number_of_allotments=request.POST.get('number_of_allotments')

    property=get_object_or_404(Property,id=id)
    roomtype=get_object_or_404(RoomType,id=rt_id)

    dayList=Inventory.objects.filter(
        room_type=rt_id,
        date__gte= datetime.date.today()
    ).order_by('date')

    pd_frame=pd.DataFrame(list(dayList.values()))
    pd_frame['occupancy']=(int(number_of_allotments)-pd_frame['allotment'])/int(number_of_allotments)
    trueList=pd_frame.to_json(orient='records')


    # for day in dayList:
    #     dateList.append(day.date)
    #     price.append(day.pricing)
    #     availability.append(day.allotment)



    return render(request,'livedb_model/typeDetail.html',{
        'property':property,
        'roomtype':roomtype,
        # 'availability':json.dumps(availability),
        # 'price':json.dumps(price),
        # 'dateList':json.dumps(dateList,default=myconverter),
        'trueList':trueList
        })

typeDetail.py

<ul>
    {% for day in trueList %}
        {% if day.availability.room %}
            <li>{{day.date}}:{{day.allotment}}:{{day.pricing.room.actual_rate.amount}}:{{day.occupancy}} </li>
        {% else %}
            <li>{{day.date}}:0:{{day.pricing.room.actual_rate.amount}} </li>
        {% endif %}
    {% endfor %}
</ul>

0 个答案:

没有答案