0

I'm learning Django and have just moved everything to Cloud9. I don't understand how to point to my templates on Cloud9?

On my local machine I have the template directory set to /home/user/etc/etc/templates and it works fine. I can't seem to grasp what the path should be when putting it in Cloud9?

ndequeker
  • 7,932
  • 7
  • 61
  • 93
  • I found my own answer! If the hierarchy in cloud9 is say /project/project/templates/template.html then the path in settings is project/templates. I was adding a slash before project. – user2670703 Aug 10 '13 at 15:39

1 Answers1

2

It's not realy good to use absolute and hardcoded path in your projects, just because you can work on different PCs or environments. So, you can define your project path according to your settings.py file. Place this somewhere in the begining of the settings.py:

import os

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))

So now you have variable PROJECT_DIR which will point to your Django project location on every PC and every env. And now, you can use it in your project in template dirs or in static files dirs like this:

#  Like this
TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates'),
)

# Or like this, pointing to one dir UP
TEMPLATE_DIRS += (
    os.path.join(PROJECT_DIR, '../templates'),
)

Also, if you settings file containt this rows:

TEMPLATE_LOADERS = (
    'django.template.loaders.app_directories.Loader',
)

Your django application will automaticaly look for templates in you applications templates dir. For example

-apps
    -main_app
        -templates
    -blog_app
        -templates

You main_app and blog app templates dirs will be detected automaticaly, without adding them to templates_path.

xelblch
  • 699
  • 3
  • 11