I have a project called ask . In it, I set the PROJECT_ROOT variable and changed the template search path:

 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(BASE_DIR) TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(PROJECT_ROOT, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ] 

The problem is that Django does not see these changes. For example, if I enter the command line of the Django environment with the command ./manage.py shell , I will see the following:

 Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from ask.settings import * >>> print PROJECT_ROOT Traceback (most recent call last): File "<console>", line 1, in <module> NameError: name 'PROJECT_ROOT' is not defined >>> print TEMPLATES [{'DIRS': ['templates'], 'APP_DIRS': True, 'OPTIONS': {'context_processors': ['django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages']}, 'BACKEND': 'django.template.backends.django.DjangoTemplates'}] 

Where did my variable PROJECT_ROOT go and why is there no path I specified in the DIRS field of the TEMPLATES dictionary?

  • It seems that the console really works with the old version of the code. Does restarting the console help? Does this start the test server? If it starts, you can place print(PROJECT_ROOT) directly in settings.py and see the result when the test server is started using the manage.py runserver : it will be displayed in STDOUT - and1er
  • 2
    make an import ask and see what ask.__file__ as expected. - jfs

0