Reputation: 7980
Suppose I have a constant defined in my models.py
as NUM_IMAGES
and I want to access that in a template within the same app. How would I go about doing this? I certainly don't want to put it in the project's settings.py
, exposing it to the entire project, nor do I particularly want to expose all settings values to the app as this might hurt modularity. So then, how would I go about referencing my NUM_IMAGES
in a template, say detail.html
?
Upvotes: 0
Views: 482
Reputation: 561
You can easily expose your constants to view by just wrapping them in context. so if you want to access NUM_IMAGES in view first import it into views.py file
from models import NUM_IMAGES
then pass it to required view
def myview(request):
#something to do
return render( request,'app/page.html',{'NUM_IMAGES':NUM_IMAGES})
Upvotes: 1