Please do not mark this question as invalid. I didn't find any question in stackoverflow with the problem mentioned below.
I have a django template. I pass the following context to it
context = {
'1_title': 'Title 1',
'2_title': 'Title 2',
'3_title': 'Title 3',
'4_title': 'Title 4',
}
return render(request, 'index.html', context)
I have a HTML file where I have a dropdown. The dropdown have values like 1,2,3,4. I have registered a onClick function to it.
I need to achieve this functionality. I will get the value in onClick function. Then I will concatenate the received value with _title and store to it a javascript variable. Now I need to use that javascript variable to reference django context. I am not able to achieve this. I have googled and did extensive searching in stackoverflow. None seem to answer my question.
The javascript function looks like this:
function getContextValue(value) {
var key = value + '_title';
return {{ key }}
}
If I select 1 in the dropdown, then the above function will have key as 1_title. I need to return the 1_title value from context which is Title 1.
For me it doesn't work and returns 1_title only. I have even tried return {{ 'key' }} . In this it returns key.
Stackoverflow community please be kind. This may be a simple question for you but not for me.