我对使用mysql的django orm有一些疑问。
这是我的models.py
from django.db import models
#电影列表
class Movieinfo(models.Model):
movienum = models.IntegerField(primary_key=True)
moviename = models.CharField(max_length=100)
movierelease_time = models.CharField(max_length=20)
movietype = models.CharField(max_length=100)
class Meta:
ordering = ["movienum"]
def __str__(self):
return self.moviename
#短评论
class Moviescritic(models.Model):
movieinfo = models.ForeignKey(Movieinfo)
movienum = models.IntegerField()
moviescrit= models.TextField()
class Meta:
ordering = ["movienum"]
def __str__(self):
return self.moviescrit
#长影评
class Movielcritic(models.Model):
movieinfo = models.ForeignKey(Movieinfo)
movienum = models.IntegerField()
movielcrittitle = models.TextField()
movielcrit = models.TextField()
class Meta:
ordering = ["movienum"]
def __str__(self):
return self.movielcrit
这是我的views.py
import logging
from django.http import HttpResponse
from django.views.generic import DetailView
from django.template import loader
from yingping.models import Moviescritic
logger = logging.getLogger('__name__')
def cdview(request):
template = loader.get_template('worldcloud.html')
movie_shu = Moviescritic.objects.filter(
movieinfo__movienum='10014'
)
content = {
'movie_shu':movie_shu,
}
return HttpResponse(template.render(content,request))
但我在html中找不到任何数据,我对django onetomany
的理解是错误的吗?
{% block worldcloud %}
{% if movie_shu %}
{% for x in movie_shu %}
<p>{{x}}</p>
{% endfor %}
{% else %}
print("err")
{% endif %}
<!--SERVICES SECTION END -->
{% endblock %}
html只找到print("error")
,当我在自己的表中找到数据时,我可以在HTML中找到数据。那我的代码有什么问题?