猿问

Django 中 html 显示的问题可能来自 view.py 结构

我正在构建一个 Django 应用程序,但我对前端的东西非常不熟悉。最终我想构建一个仪表板,但现在我在构建一个与我希望它显示的内容相匹配的视图方面有些困难。


到目前为止,视图类已很好地转移到前端(运行服务器时没有错误),但它不显示值,而是显示黑点。这里附上我的模型、html 代码以及我的 view.py


class Classification(models.Model):

    Class = models.CharField(max_length=10, primary_key=True)

    revenue_proportion = models.FloatField(default=0)

    Quantity_of_item = models.IntegerField(default=0)

    percentage_of_items = models.FloatField(default=0)

    cumul_percentage_of_items = models.FloatField(default=0)

    inventory_dollars = models.FloatField(default=0)

    inventory_dollars_percentage = models.FloatField(default=0)

    cumul_inventory_dollars_percentage = models.FloatField(default=0)

    average_margin = models.FloatField(default=0)

    average_sales_week = models.FloatField(default=0)

    weekly_percentage_sales = models.FloatField(default=0)


    def __str__(self):

        return self.Class



class stock_anormal(models.Model):

    reference_anormales = models.CharField(max_length=10, primary_key=True)

    stock_alerte_calcule = models.FloatField(default=0)

    stock_alerte_recommande = models.FloatField(default=0)

    en_alerte = models.FloatField(default=0)


    def __str__(self):

        return self.reference_anormales



class stock_negatif(models.Model):

    reference_negatives = models.CharField(max_length=10,primary_key=True)

    stock_alerte_calcule = models.FloatField(default=0)

    stock_alerte_recommande = models.FloatField(default=0)

    risque_de_rupture = models.FloatField(default=0)


    def __str__(self):

        return self.reference_negatives



largeQ
浏览 96回答 1
1回答

米琪卡哇伊

您在 for 循环中引用了错误的变量。您必须使用该单词后声明的变量名for来引用循环内的实例。<ul>&nbsp; &nbsp; {% for t in top_sellers_list %}&nbsp; &nbsp; &nbsp; &nbsp; <li><a href="/dashboard/topsellers/{{ t.id }}/">{{t.avg_per_week }}</a></li>&nbsp; &nbsp; {% endfor %}</ul><ul>&nbsp; &nbsp; {% for c in classification %}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<li><a href="/dashboard/classifications/{{ c.id }}/"> {{c.inventory_dollars }}</a></li>&nbsp; &nbsp; {% endfor %}</ul><ul>&nbsp; &nbsp; {% for a in anormal %}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<li><a href="/dashboard/anormals/{{ a.id }}/">{{ a.reference_anormales }}</a></li>&nbsp; &nbsp; {% endfor %}</ul><ul>&nbsp; &nbsp; {% for n in negat %}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<li><a href="/dashboard/negats/{{ n.id }}/">{{ n.reference_negatives }}</a></li>&nbsp; &nbsp; {% endfor %}</ul><ul>&nbsp; &nbsp; {% for s in service %}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<li><a href="/dashboard/services/{{ s.id }}/">{{ s.reference_service }}></a></li>&nbsp; &nbsp; {% endfor %}</ul>请注意,我也更改了链接,仅作为示例
随时随地看视频慕课网APP

相关分类

Html5
我要回答