python - trying to display data from database, only getting blank page -
i'm trying display data data base. here's template:
<ul> {% post in latest_post %} <li>{{ post.id }} : {{ post.post_body }}</li> {% endfor %} </ul>
here's subview:
def success(request): latest_post = models.post.objects template = loader.get_template('success.html') context = { 'lastest_post': latest_post } return httpresponse(template.render(context, request))
but i'm getting blank page. why?
here's model i'm trying display data:
from django.db import models class post(models.model): creation_date = models.datetimefield(null=true) post_name = models.charfield(max_length=30, null=true) post_title = models.charfield(max_length=50, null=true) post_body = models.textfield(max_length=2000, null=true) post_pass = models.charfield(max_length=100, null=true) post_im = models.charfield(max_length=15, null=true) post_image = models.charfield(max_length=100) image_width = models.integerfield(null=true) image_height = models.integerfield(null=true) image_size = models.integerfield(null=true) image_sha224 = models.charfield(max_length=28, null=true)
you need call all
method of model:
latest_post = models.post.objects.all() # ^^^^^
if intend return non-all result, should use filter
.
read more making queries here
Comments
Post a Comment