In my context_processors.py page I am trying to pass a value from one function to another, but it is not working and I cannot understand why it does not work.
Here is my context_processors.py page code:
def get_current_page_value(request):
if request.get_full_path() == settings.MENU_DETAIL_LINK_AA_DETAILS:
return {'current_page_value02':settings.MENU_DETAIL_VALUE_AA_DETAILS}
elif request.get_full_path() == settings.MENU_DETAIL_LINK_BB_DETAILS:
return {'current_page_value02':settings.MENU_DETAIL_VALUE_BB_DETAILS}
else:
return {'current_page_value02':settings.MENU_DETAIL_VALUE_CC_DETAILS}
def resume_menu_list(request):
if not request.user.is_authenticated():
return {}
try:
current_page_val = current_page_value02
How can I pass the value current_page_value02 from get_current_page_value(request) to resume_menu_list(request)?
I have declared the values in my settings page:
'X.core.context_processors.get_current_page_value',
'X.core.context_processors.resume_menu_list',
If you want to access the value returned by a function, you have to call it.
get_current_page_value()
This will return a dictionary, and you can then access individual keys
get_current_page_value()['current_page_value02']
So you could include get_current_page_value()['current_page_value02']
in your context processor.
Context processors really should be distinct, and not rely on each other. If you do call the get_current_page_value
function inside the context processor, then it will be called twice -- once as a context processor, and once inside resume_menu_list
. That doesn't seem right to me, but I'm not sure what to suggest, as I don't understand exactly what you're trying to achieve.