Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

547k answers

4 comments

35.4k users

...