Plantillas DJANGO no encontradas
Publicado por Bego (1 intervención) el 24/05/2017 14:41:09
Hola.
Intento hacer uso de una plantilla básica en DJANGO 1.11 pero no consigo que DJANGO la encuentre.
He modificado el fichero settings.py
En el directorio que indico tengo creado el fichero plantilla01.html
Lo he mapeado en URL.PY :
Arranco el servidor y siempre me indica que no encuentra la plantilla plantilla01.html
Este es el log del error :
Environment:
Request Method: GET
Request URL: http://localhost:8000/pagina/
Django Version: 1.11.1
Python Version: 3.6.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine :
This engine did not provide a list of tried templates.
Traceback:
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\BEGONA\WORKSPACE\DJANGO_V6\src\DJANGO_V6\formulario.py" in paginaPlantilla
9. plantilla = get_template('plantilla01.html')
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\loader.py" in get_template
25. raise TemplateDoesNotExist(template_name, chain=chain)
Exception Type: TemplateDoesNotExist at /pagina/
Exception Value: plantilla01.html
He probado a asignar el directorio de TEMPLATE_DIRS de muchas formas, pero no hay manera de que DJANGO encuentre la plantilla plantilla01.html
Gracias de antemano.
Un saludo.
Intento hacer uso de una plantilla básica en DJANGO 1.11 pero no consigo que DJANGO la encuentre.
1
2
3
4
5
6
7
8
9
10
from django.http import HttpResponse
from django.template import Context
from django.template.loader import get_template
def paginaPlantilla(request):
plantilla = get_template('plantilla01.html')
return HttpResponse (plantilla.render(Context({'nombre':'cecilio'})))
He modificado el fichero settings.py
1
2
3
4
5
6
7
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
'C:/BEGONA/WORKSPACE/DJANGO_V6/src/Plantillas'
)
En el directorio que indico tengo creado el fichero plantilla01.html
Lo he mapeado en URL.PY :
1
2
3
4
5
6
from django.conf.urls import url
from DJANGO_V6.formulario import paginaPlantilla
urlpatterns = [
url(r'^pagina/', paginaPlantilla),
]
Arranco el servidor y siempre me indica que no encuentra la plantilla plantilla01.html
Este es el log del error :
Environment:
Request Method: GET
Request URL: http://localhost:8000/pagina/
Django Version: 1.11.1
Python Version: 3.6.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine :
This engine did not provide a list of tried templates.
Traceback:
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\BEGONA\WORKSPACE\DJANGO_V6\src\DJANGO_V6\formulario.py" in paginaPlantilla
9. plantilla = get_template('plantilla01.html')
File "C:\Users\profesor.FORMACION0\AppData\Local\Programs\Python\Python36\lib\site-packages\django\template\loader.py" in get_template
25. raise TemplateDoesNotExist(template_name, chain=chain)
Exception Type: TemplateDoesNotExist at /pagina/
Exception Value: plantilla01.html
He probado a asignar el directorio de TEMPLATE_DIRS de muchas formas, pero no hay manera de que DJANGO encuentre la plantilla plantilla01.html
Gracias de antemano.
Un saludo.
Valora esta pregunta


0