Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

python - Django table rendering blank rows

I've searched far and wide, and haven't come up with a solution despite this probably being a simple fix.

Models.py:

class Leaderboard(models.Model):
    name = models.CharField(max_length=25)

    def __str__(self):
        return self.name

class Score(models.Model):
    leaderboard = models.ForeignKey(Leaderboard, on_delete=models.CASCADE)
    player_name = models.CharField(max_length=25)
    score = models.IntegerField()
    time_set = models.DateTimeField(null=True, blank=True)

    def __str__(self):
        return f"{self.player_name} - {self.leaderboard} [{self.score}]"

views.py

def index(response, name):
    # ls = Leaderboard.objects.get(name=name)
    sorted = Leaderboard.objects.filter(name=name).order_by('-score')
    return render(response, "highscores/leaderboard_ranks.html", {"ls": sorted})

And the relevant template part of the code.

{% for item in ls %}
<tr>
<td></td>
<td>{{item.player_name}}</td>
<td>{{item.score}}</td>
<td>{{item.time_set}}</td>
</tr>
{% endfor %}

And this just outputs blank rows in the table. What am I missing?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...