If you are in the view and want to retrieve the app name using Python ( the app name will be used for further logic ), how would you do it ?
You could do:
from django.core.urlresolvers import resolve .... resolve(request.path).app_name
See How to get current application in Django and resolve()
EDIT: You can now use request.resolver_match.app_name which avoids resolving a second time and avoids an import. Do it this way:
request.resolver_match.app_name
You can get application name from model: Book._meta.app_label
.
I've found in django/contrib/admin/widgets.py
:
class RelatedFieldWidgetWrapper(forms.Widget): ... def get_context(self, name, value, attrs): from django.contrib.admin.views.main import IS_POPUP_VAR, TO_FIELD_VAR rel_opts = self.rel.model._meta info = (rel_opts.app_label, rel_opts.model_name) ... ...
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