Django - Multiple apps on one webpage?
A django app doesn't really map to a page, rather, it maps to a function. Apps would be for things like a "polls" app or a "news" app. Each app should have one main model with maybe a couple supporting ones. Like a news app could have a model for articles, with supporting models like authors and media.
If you wanted to display multiple, you would need an integration app. One way to do this is to have a "project" app next to your polls and news apps. The project app is for your specific website- it is the logic that is specific to this application. It would have your main urls.py, your base templat(s), things like that. If you needed information from multiple apps in one page, you have to have a view that returns info from multiple apps. Say, for example, that you have a view that returns the info for a news article, and one that returns info for a poll. You could have a view in your project app that calls those two view functions and sticks the returned data into a different template that has spots for both of them.
In this specific example, you could also have your polls app set up so that its return info could be embedded- and then embed the info into a news article. In this case you wouldn't really have to link the apps together at all as part of your development, it could be done as needed on the content creation end.
Each page or view should be contained in a single app, however, you can load in other apps from within an app. This does however make that app dependent on the other apps being present.
So if you wanted to display something from an app called "otherapp" in this app called "thisapp" then in thisapp.views you would simply add an import to the top of the file like this
from otherapp.models import OtherAppModel
Once you've done the import you can then access that models fields and methods. Also make sure you've added all of the apps to the INSTALLED_APPS list in your settings file.
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.