add SetApplicationName middleware for nav use
This commit is contained in:
13
procat2/middleware.py
Normal file
13
procat2/middleware.py
Normal 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]
|
||||||
@ -46,6 +46,7 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
|
'procat2.middleware.SetApplicationName',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'procat2.urls'
|
ROOT_URLCONF = 'procat2.urls'
|
||||||
@ -54,8 +55,7 @@ TEMPLATES = [
|
|||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': ['templates'],
|
'DIRS': ['templates'],
|
||||||
#'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
#'DIRS': [os.path.join(BASE_DIR, 'templates')],
|
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
'django.template.context_processors.debug',
|
'django.template.context_processors.debug',
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<div class="container navigation">
|
<div class="container navigation">
|
||||||
SEPARATE NAV for {{ user }}
|
SEPARATE NAV for "{{ user }}" in app "{{ request.current_app }}"
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user