2015-07-03 56 views
1

我試圖在我的Django項目中使用unipath模塊,因爲它在Django書籍的兩勺中提到,並且某些作品不符合預期。 在我的settings.py我有這樣的:Django模板和unipath

from unipath import Path 

    BASE_DIR = Path(__file__).ancestor(2) 

    TEMPLATES = [ 
     { 
      'BACKEND': 'django.template.backends.django.DjangoTemplates', 
      'DIRS': [(BASE_DIR.child('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', 
       ], 
      }, 
     }, 
    ] 

    STATIC_ROOT = BASE_DIR.child('static') 
    MEDIA_ROOT = BASE_DIR.child('media') 

有了這樣的設置,我得到TemplateDoesNotExist例外:

Using loader django.template.loaders.filesystem.Loader: 

    /var/www/(Path('/home/user/my_project/project/templates'),)/myapp/index.html (File does not exist) 

我在做什麼錯?

回答

2

終於解決了這個問題! 需要將settings.py中的TEMPLATES''DIRS'字符串編輯爲:

'DIRS': (BASE_DIR.child('templates'),),