I built my Django homepage’s view using direct_to_template plus lots of extra_context, code example:
extra_context = {
'photo': Photo.objects.filter(section='example')[:5],
'video': Video.objects.filter(section='example')[:5],
'post': Post.objects.filter(section='example')[:5],
'page': Page.objects.get(slug='example'),
'artists': Artist.objects.all(),
}
url(r'^$', direct_to_template, {'template': 'homepage.html', 'extra_context': extra_context}, name='homepage')
But content in homepage always not the newest, I have to restart dev server or gunicorn in production to make it diaplay newest content. Where does the problem lie in?
That’s because your content is evaluated only once: when
urls.pyis imported. I think you need a normal view here. Or you can pass callables (or other lazy objects) to context, not evaluated ones.