For a GET request received at some url, how can we display user-search-form, new-post-form and friends-list together?
You can request to render any template from any view. Django will search for the template through every registered app for a template
directory. Or you can specify your own template directories using TEMPLATE_DIR
, but it seems like you already knew this from your next question....
If we do that by some project-level common view, what about the app-level views?
Could you please try to explain this question in more depth?
I have read that the {% include %} tag is handy for building template from several "subtemplates", but what about the different variables the included templates take?
From the docs:
An included template is rendered with the context of the template that’s including it.
If you have a partial template, intended for including, like:
# hello.html
<h2>Hello {{ person.name }}</h2>
and another template is including it:
# greeting.html
{% include 'hello.html' %}
render_to_response('greeting.html', {})
the output will be Hello
because you do not have a person
in the template context
I don't quite understand your second bullet point. Your django package is just a python package. If you had two apps you can import code any way you choose, importing modules from your two different apps.
For example, in most projects I end up having a common
app. This usually contains utilities used throughout the whole django project. It usually contains my base test classes.
In your apps you can just import
from yourproject.common.utils import a_function
To help with decoupling django provides a signals framework. Your apps can emit and receive signals.
Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.