Recent comments


Syndicate


Follow Me

Twitter Facebook

Django: Setting template's path dynamically

I was trying Django the other night and the tutorial from their site mentioned to set the absolute directory to all of my template files on a variable called TEMPLATE_DIRS which is inside the settings.py.

Now I already read somewhere else that this is because you can specify your template files to be outside of your Django project. But for the sample I was working on, I want it to be inside the project's folder so I added a template folder there and to tell Django to automatically detect and set the path to my templates folder, I added it like this:

TEMPLATE_DIRS = ( os.path.join(os.getcwd(), "templates"), )

What this does is it joins the current directory where the settings.py file resides and concatenates it with the templates folder. You can probably put this inside a function when you start adding multiple template directories.

oh, I've been interested on

oh, I've been interested on this framework but I don't know more about python. I've been trying python and reading articles/tuts about it but theres always in my way, for example procastinating.Aynways, it's good that you've/you'll cover this framework. Nice.

Yeah, Django is cool. But it

Yeah, Django is cool. But it doesn't have the agnostic personality, but I like it though and falling in love with it each day. 

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.