Django - Multiple apps on one webpage?
django, python
Solution
You could do something like this to display app data on a page.
views.py
def home(request, template='path/to/template'):
context = {
'polls': Poll.objects.all(),
'galleries': Gallery.objects.all(),
}
return (request, template, context)
In the template:
{% for poll in polls %}
{{ poll }}
{% endfor %}
{% for gallery in galleries %}
{{ gallery }}
{% endfor %}
urls.py
url('home/$', app.views.home, name='home')
But if you want to display the information like on a sidebar where it will be displayed all the time, then you'd want to use template tags.
Problem
I've looked all over the net and found no answer. I'm new to Django. I've done the official tutorial and read many more but unfortunately all of them focus on creating only one application. Since it's not common to have a page as a single app, I would like to ask some Django guru to explain how I can have multiple apps on a webpage. Say I go to mysite.com and I see a poll app displaying a poll, gallery app displaying some pics, news app displaying latest news etc, all accessed via one url. I know I do the displaying in template but obviously need to have access to data. Do I create the view to return multiple views? Any advice, links and examples much appreciated.