I'm trying to get the current application name (the application that contains the current view) from a context processor because all my application have their own Webdoor models, but they all have the same attributes (some values differ). The values from Webdoor are used on every page, so I wanted to get it inside my custom context processor to make this task easier than calling it on every view. Not only it, but I could use it for other similar tasks. Once I already know the model name, I would just need the app to call it using the get_model method.
Anyone has any idea of how to do it?
Thanks!
A nice place to figure what is the current view is the process_view() middleware method, which also happens to be a great place to add a request variable. E.g.:
class CurrentViewApplicationName(object):
def process_view(self, request, view_func, view_args, view_kwargs):
request.current_app = view_func.__module__.split('.')[0]
Will set request.current_app to testapp if view_func is testapp.views.some_view. It might not be bullet proof, some apps have views in submodules etc ... But this should be a nice starter for you to tweak to your project specific needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With