Reputation: 3025
I have a list of urls that I have imported in my settings.py file via:
from myproject.image_folders_link import Links
Now my image_folders_link
contains the following constants:
MY_image_doctors_link = "http://www.mywebsite.com/images/doctors"
MY_image_patients_link = "http://www.mywebsite.com/images/patients"
Now I want to use it in my Django template. How I can pass this?
Upvotes: 2
Views: 280
Reputation: 53999
If you want a set of constants available in all of your template, you should write a "context processor".
I don't really understand what variables you are trying to add, but in general you create a new file in one of your apps called context_processors.py
:
from myproject.image_folders_link import Links
def template_links(request):
return {
"MY_image_doctors_link": "http://www.mywebsite.com/images/doctors",
...
}
Now add it to the TEMPLATE_CONTEXT_PROCESSORS
setting in your settings.py
:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'myapp.context_processors.template_links',
)
and you can call those variables in all your templates:
{{ MY_image_doctors_link }}
Upvotes: 3