可以从Django模板中的views.py获取值。 获取标签及其值不起作用。如何获得它?
在modules.py
中class Article(models.Model):
pub_date = models.DateField()
headline = models.CharField(max_length=200)
content = models.TextField()
reporter = models.ForeignKey(Reporter, on_delete=models.CASCADE)
def __str__(self):
return self.headline
在views.py
中def articlesindex(request):
data = Articles.objects.all().last()
return render(request, 'Articles\index.html', {'articles':data}
在index.html
{{ articles.headline }} //gives you the value
{{ articles.headline.label_tag }} //does not give you the name "headline"