Klanestro
Klanestro

Reputation: 3215

point to a custum setting in the template

I want to create settings in the settings.py file that i can access in the templates that i use without passing the setting in ,in the views.py using django

settings.py
CSS_FOLDER_ROOT = "/home/brian/Projects/RaffleThis/RaffleGym/stylesheets"

CSS_FOLDER_URL = SITE_DOMAIN + "/CSS/"

I want the server to serve the files from CSS_FOLDER_ROOT when HttpRequest is sent

working on the django template .html file and the views.py file

Upvotes: 0

Views: 59

Answers (1)

Rod Xavier
Rod Xavier

Reputation: 4043

I guess one way to do this is by creating a context processor.

Create a context_processors.py somewhere in your project

import settings    
def css_url(request):
    return {'CSS_URL': settings.CSS_URL}

Add the context processor in your settings

CSS_FOLDER_ROOT = "/home/brian/Projects/RaffleThis/RaffleGym/stylesheets/"
CSS_URL = '/css/'

TEMPLATE_CONTEXT_PROCESSORS += (
    "django_app.context_processors.css_url",
)

Then you can use something like this in your templates.

<link rel="stylesheet" href="{{ CSS_URL }}<filename.css>" />

Upvotes: 1

Related Questions