How to add app to all pages in django?
I have an app called lastapp that I would like it to be viewable 开发者_如何学运维on all pages. It renders base.html so it's available on all apps. So far I've tried adding it to the urls.py like this:
urlpatterns = patterns('',
(r'^first/$', firstapp, lastapp),
(r'^last/$', lastapp),
)
But when I go to /first/ it gives me the error: Error, 'function' not iterable. It shows fine when going to /last/. If I remove lastapp from the /first/ site in urls.py, then firstapp shows fine also. Is there a special way to do this? Thanks in advance.
What exactly are you trying to do?
All installed applications are available in your project, but the application by it self does not return any data to the template, that's the job of the views which are part of that application.
My guess is that firstapp
and lastapp
are rather views then apps.
If that is a case, context processors make it possible to always pass certain data to a template.
So, create a context processor out of lastapp
and set it in TEMPLATE_CONTEXT_PROCESSORS in settings.py.
I think what you need is probably Middleware.
精彩评论