WebFaction
Community site: login faq

I have a project and what I want to do is to make the urls to the TEMPLATE_DIRS more flexible, doing this:

import os
directorio = os.getcwd()

if (directorio.find('djangoProjects') != -1):
    DEBUG = True
else:
    DEBUG = False

TEMPLATE_DEBUG = DEBUG

#############################################
rutaHomeProject = directorio + '/../'
#############################################

... and then ...

TEMPLATE_DIRS = (
    rutaHomeProject + "fabricaBolsas/templates",
    rutaHomeProject + "fabricaBolsas/login/templates",
    rutaHomeProject + "fabricaBolsas/stock/templates",
    )

Doing this I don't have to modify the settings when deploying. The problem is that when I use this and acces to the web I get a template does not exist, because in the TEMPLATE_DIRS , the url isn't filled with the getcwd() command. But when I make a python manage.py shell, and import settings the settings.rutaHomeProject has the correct value. I don't know what I'm doing wrong.

PD: Sorry for my english, I'm from Argentina.....

asked 28 Nov '10, 07:52

Luchi
4147
accept rate: 20%


It is hard to tell without looking at your code and directory structure, but you can try changing your TEMPLATE_DIRS to the following:

TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), "../fabricaBolsas/templates"),
    os.path.join(os.path.dirname(__file__), "../fabricaBolsas/login/templates"),
    os.path.join(os.path.dirname(__file__), "../fabricaBolsas/stock/templates"),
)

If that doesn't resolve the problem, feel free to open a ticket and we'll take a look at your settings.

permanent link

answered 28 Nov '10, 08:29

aaronh ♦♦
1.3k3
accept rate: 34%

1

I like just setting a variable at the top of settings.py, then it can be used for other statements as well such as your MEDIA_ROOT variable. Such as:

PROJECT_ROOT = os.path.normpath(os.path.dirname(file))

Then all you have to do for your template path is:

TEMPLATE_DIRS = (
    os.path.join(PROJECT_ROOT, "../fabricaBolsas/templates"),
)
A little less to type and accomplishes the same thing.

(28 Nov '10, 15:28) bmeyer71 ♦♦

Thanks. That's works perfectly

permanent link

answered 28 Nov '10, 13:43

Luchi
4147
accept rate: 20%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×19
×16
×1
×1
×1

question asked: 28 Nov '10, 07:52

question was seen: 8,455 times

last updated: 28 Nov '10, 15:28

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM