python - TemplateDoesNotExist at / base.html -


friends. try repeat doing example of project in book: "learning django web development" jaiswal, sanjeev.

running server such exception: templatedoesnotexist @ /base.html

templatedoesnotexist @ / base.html  request method:     request url:    http://127.0.0.1:8000/ django version:     1.8.3 exception type:     templatedoesnotexist exception value:    base.html  exception location: c:\python34\lib\site-packages\django\template\loader.py in get_template, line 46 python executable:  c:\python34\python.exe python version:     3.4.3 python path:      ['c:\\dj\\mytweets', 'c:\\windows\\system32\\python34.zip', 'c:\\python34\\dlls', 'c:\\python34\\lib', 'c:\\python34', 'c:\\python34\\lib\\site-packages']  server time:    tue, 14 jul 2015 14:01:27 +0300 

template-loader postmortem

django tried loading these templates, in order:      using loader django.template.loaders.filesystem.loader:     using loader django.template.loaders.app_directories.loader:         c:\python34\lib\site-packages\django\contrib\admin\templates\base.html (file not exist)         c:\python34\lib\site-packages\django\contrib\auth\templates\base.html (file not exist) 

my settings.py file:

import os  settings_path = os.path.dirname(__file__) project_path = os.path.join(settings_path, os.pardir) project_path = os.path.abspath(project_path) template_path = os.path.join(project_path, "templates")  secret_key = 'khcr3h6u+ghi+rtb+g_(mvgq!mtn9u4&%=hu20vt2*u(p8-kde'  debug = true template_debug = true allowed_hosts = []  installed_apps = (     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'tweets', )  middleware_classes = (     'django.contrib.sessions.middleware.sessionmiddleware',     'django.middleware.common.commonmiddleware',     'django.middleware.csrf.csrfviewmiddleware',     'django.contrib.auth.middleware.authenticationmiddleware',     'django.contrib.auth.middleware.sessionauthenticationmiddleware',     'django.contrib.messages.middleware.messagemiddleware',     'django.middleware.clickjacking.xframeoptionsmiddleware',     'django.middleware.security.securitymiddleware', )  root_urlconf = 'mytweets.urls'  templates = [     {         'backend': 'django.template.backends.django.djangotemplates',         'dirs': [os.path.join(project_path, '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',             ],         },     }, ]  wsgi_application = 'mytweets.wsgi.application'  databases = {     'default': {         'engine': 'django.db.backends.sqlite3',         'name': os.path.join(project_path, 'db.sqlite3'),     } }  language_code = 'en-us'  time_zone = 'utc'  use_i18n = true  use_l10n = true  use_tz = true  static_url = '/static/' staticfiles_dirs = (     os.path.join(         os.path.dirname(__file__),         'static',     ), )  template_dirs = (     template_path, )  template_loaders = (     'django.template.loaders.filesystem.loader',     'django.template.loaders.app_directories.loader', ) 

i tried change settings.py in such way too:

changed settings.py:

import os  base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) template_path = os.path.join(base_dir, "templates")  secret_key = 'khcr3h6u+ghi+rtb+g_(mvgq!mtn9u4&%=hu20vt2*u(p8-kde'  debug = true template_debug = true allowed_hosts = []  installed_apps = (     'django.contrib.admin',     'django.contrib.auth',     'django.contrib.contenttypes',     'django.contrib.sessions',     'django.contrib.messages',     'django.contrib.staticfiles',     'tweets', )  middleware_classes = (     'django.contrib.sessions.middleware.sessionmiddleware',     'django.middleware.common.commonmiddleware',     'django.middleware.csrf.csrfviewmiddleware',     'django.contrib.auth.middleware.authenticationmiddleware',     'django.contrib.auth.middleware.sessionauthenticationmiddleware',     'django.contrib.messages.middleware.messagemiddleware',     'django.middleware.clickjacking.xframeoptionsmiddleware',     'django.middleware.security.securitymiddleware', )  root_urlconf = 'mytweets.urls'  templates = [     {         'backend': 'django.template.backends.django.djangotemplates',         'dirs': [os.path.join(base_dir, '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',             ],         },     }, ]  wsgi_application = 'mytweets.wsgi.application'  databases = {     'default': {         'engine': 'django.db.backends.sqlite3',         'name': os.path.join(base_dir, 'db.sqlite3'),     } }  language_code = 'en-us'  time_zone = 'utc'  use_i18n = true  use_l10n = true  use_tz = true   static_url = '/static/' staticfiles_dirs = (     os.path.join(         os.path.dirname(__file__),         'static',     ), ) 

my project structure:

my project structure:

views.py:

from django.views.generic import view django.shortcuts import render   class index(view):     def get(self, request):         params = {}         params['name'] = 'django'         return render(request, 'base.html', params) 

urls.py:

from django.conf.urls import patterns, include, url django.contrib import admin tweets.views import index admin.autodiscover()  urlpatterns = patterns('',     url(r'^$', index.as_view()),     url(r'^admin/', include(admin.site.urls)), ) 

traceback:

template loader error: django tried loading these templates, in order: using loader django.template.loaders.filesystem.loader: using loader django.template.loaders.app_directories.loader: c:\python34\lib\site-packages\django\contrib\admin\templates\base.html    (file not exist) c:\python34\lib\site-packages\django\contrib\auth\templates\base.html (file not exist)    traceback: file "c:\python34\lib\site-packages\django\core\handlers\base.py" in get_response   132.response = wrapped_callback(request, *callback_args, **callback_kwargs) file "c:\python34\lib\site-packages\django\views\generic\base.py" in view   71.return self.dispatch(request, *args, **kwargs) file "c:\python34\lib\site-packages\django\views\generic\base.py" in dispatch   89.return handler(request, *args, **kwargs) file "c:\dj\mytweets\tweets\views.py" in   9.return render(request, 'base.html', params) file "c:\python34\lib\site-packages\django\shortcuts.py" in render 67.template_name, context, request=request, using=using) file "c:\python34\lib\site-packages\django\template\loader.py" in render_to_string  98.template = get_template(template_name, using=using) file "c:\python34\lib\site-packages\django\template\loader.py" in get_template   46.raise templatedoesnotexist(template_name)  exception type: templatedoesnotexist @ / exception value: base.html 

please, give advice, should change rendered page?

i'm not familiar book using, can't give advice based on that. if book django 1.7, find easier use django 1.7 instead of django 1.8, @ least when beginning django.

if want stick django 1.8, here's how fix error seeing:

your settings.py file has mixture of old templates settings, template_dirs , template_loaders (django <= 1.7), , new settings under templates (django 1.8+).

first, remove old settings template_dirs , template_loaders.

secondly, looks if dirs incorrect in templates setting.

define base_dir, should included in settings.py default when run ./manage.py startproject

base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 

then change templates to

templates = [     {         'backend': 'django.template.backends.django.djangotemplates',         'dirs': [os.path.join(base_dir, 'templates')],         ... 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -