Question

I have a base.html which is inherited by all other pages. and the footer of all pages are also coming from base.html

now i want to show in footer some objects from db. so i need to render some objects from db to base.html. then i thought, i will write my own tag which does the job.

i did this custom tag:

def berlin_tag():
  loc_berlin = Location.objects.filter(stadt="Berlin").order_by('-id')[:4]
  return loc_berlin

I am returning 4 recent locations in berlin.

then in my template:

{% berlin_tag %}

but now i am stuck how to show it in template. at the moment, {% berlin_tag %} is showing [, , ].

how can i loop over all 4 objects and show them in template? please help

Était-ce utile?

La solution

Assignment tags do exactly this.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top