add SetApplicationName middleware for nav use

This commit is contained in:
Seth Ladygo
2019-03-12 18:08:01 -07:00
parent 626570ffe3
commit d55272bced
3 changed files with 16 additions and 3 deletions

13
procat2/middleware.py Normal file
View File

@ -0,0 +1,13 @@
# https://docs.djangoproject.com/en/2.1/topics/http/middleware/
# https://stackoverflow.com/questions/12596722/django-identify-app-in-template
class SetApplicationName(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)
def process_view(self, request, view_func, view_args, view_kwargs):
request.current_app = view_func.__module__.split('.')[0]

View File

@ -46,6 +46,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'procat2.middleware.SetApplicationName',
]
ROOT_URLCONF = 'procat2.urls'
@ -54,8 +55,7 @@ TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
#'APP_DIRS': True,
#'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',

View File

@ -1,3 +1,3 @@
<div class="container navigation">
SEPARATE NAV for {{ user }}
SEPARATE NAV for "{{ user }}" in app "{{ request.current_app }}"
</div>