为什么这不能正常显示?

时间:2018-04-11 16:03:03

标签: python django

我真的不确定为什么没有显示带有超链接的乐队名称,所有出现的都是“乐队列表”,其下面没有任何内容。

数据库中有数据,但没有显示任何内容。

这是模板。

{% block content %}
<h1>Band List</h1>
{% for band in bands %}
{{ band.id }}
<h3><a href='/bandlist/{{band.id}}'>{{ band.bandname }}</a></h3>
{% endfor %}

{% endblock %}

以下是我的views.py

from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render, render_to_response, redirect
from django.contrib.auth.decorators import login_required
from django.contrib.auth import login, authenticate
from django.shortcuts import render, redirect
from polls.forms import NormalSignUpForm, VenueSignUpForm, BLSignUpForm, BMSignUpForm, ProfileForm
from django.contrib.auth import get_user_model
from django.views.generic.detail import SingleObjectMixin
from django.views.generic import UpdateView, TemplateView
from django.utils.decorators import method_decorator
from django.db.models.signals import post_save
from .models import *
from polls.models import User
from django.http import Http404

def bandlist(request):
    query = Band.objects.all()
    print(query)
    args =  {'query': query}
    return render(request, 'bandlist.html', args)

以下是我的models.py

class Band(models.Model):
    bandname = models.CharField(max_length = 50)   
    description = models.TextField()
    picture = models.ImageField()
    members = models.ManyToManyField('User')

    def __str__(self):
        return self.bandname

如果有人能对此作出澄清,那将非常有帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

此行return render(request, 'bandlist.html', args)向模板发送名为context的{​​{1}}对象。 所以你的模板代码应该有:

args