0
votes

I´m having my production site on Heroku.

The app can find templates defined with url in the urlpatterns of the urls.py file.

Like: url(r'^contactreport/$', views.ContactosView, name="contactos"),

But not the ones defined with path.

Like: path('inventario/', views.InventarioView, name="inventario"),

Settings

This is my static folder config in settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

This is my middleware (but I think it´s not the problem).

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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',
]

The error I get

When I try the links to thos pages I get:

TemplateDoesNotExist

django.template.loaders.filesystem.Loader: /app/templates/catalog/tareas.html (Source does not exist)

The html template exists.

The full traceback

Environment:

Request Method: GET Request URL: https://afternoon-wildwood-39943.herokuapp.com/catalog/tareas/

Django Version: 2.1.3 Python Version: 3.7.0 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'catalog.apps.CatalogConfig', 'rest_framework', 'django.urls', 'django.contrib.humanize', 'catalog.templatetags'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', '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 django: * django.template.loaders.filesystem.Loader: /app/templates/catalog/tareas.html (Source does not exist) * django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/admin/templates/catalog/tareas.html (Source does not exist) * django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/templates/catalog/tareas.html (Source does not exist) * django.template.loaders.app_directories.Loader: /app/catalog/templates/catalog/tareas.html (Source does not exist) * django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.7/site-packages/rest_framework/templates/catalog/tareas.html (Source does not exist)

Traceback:

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 126. response = self.process_exception_by_middleware(e, request)

File "/app/.heroku/python/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response 124. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/app/.heroku/python/lib/python3.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 21. return view_func(request, *args, **kwargs)

File "/app/catalog/views.py" in TareasView 630. 'mis_tareas_atrasadas': mis_tareas_atrasadas,

File "/app/.heroku/python/lib/python3.7/site-packages/django/shortcuts.py" in render 36. content = loader.render_to_string(template_name, context, request, using=using)

File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader.py" in render_to_string 61. template = get_template(template_name, using=using)

File "/app/.heroku/python/lib/python3.7/site-packages/django/template/loader.py" in get_template 19. raise TemplateDoesNotExist(template_name, chain=chain)

Exception Type: TemplateDoesNotExist at /catalog/tareas/ Exception Value: catalog/tareas.html

One of the views that gives problems

@login_required
def TareasView(request):
    tareas_filter_form = TareasFilterForm(request.POST)
    tareas_form = FormularioTareas(request.POST)
    tareas = Tareas.objects.all()
    tareas = tareas.order_by("-fecha_creacion")
    mis_tareas_por_hacer = tareas.filter(resuelto=False).count()

    desde = date.today() - timedelta(days=365)
    hasta = date.today() - timedelta(days=1)
    mis_tareas_atrasadas = tareas.filter(fecha_limite__range=[desde, hasta]).count()

    if request.method == "POST" and 'filtrar_tareas' in request.POST:
        tareas_filter_form = TareasFilterForm(request.POST)
        if tareas_filter_form.is_valid():
            estatus_resuelto = tareas_filter_form.cleaned_data["estatus_resuelto"]
            destinatario = tareas_filter_form.cleaned_data["destinatario"]
            busca_titulo = tareas_filter_form.cleaned_data["busca_titulo"]
            if destinatario:
                tareas = tareas.filter(destinatario=destinatario)

            if estatus_resuelto != "Todas":
                tareas = tareas.filter(resuelto=estatus_resuelto)

            tareas = tareas.filter(titulo__icontains=busca_titulo)

    return render(request, 'catalog/tareas.html', {
        'tareas_form': tareas_form,
        'tareas_filter_form': tareas_filter_form,
        'tareas': tareas,
        'mis_tareas_por_hacer': mis_tareas_por_hacer,
        'mis_tareas_atrasadas': mis_tareas_atrasadas,

    })

Any clues welcome. Thanks in advance!

1
Did you type from django.urls import path in your urls.py?Aurélien
@Aurélien Yes I did.Francisco Ghelfi
What do you mean, it can't find the templates? What do template have to do with this? What exactly happens when you go to that URL?Daniel Roseman
@DanielRoseman Just updated the postFrancisco Ghelfi
If you get TemplateDoesNotExist, then please show the view that is failing, the full error message, and the project layout. It will make no difference to this error if you use path() or url().Alasdair

1 Answers

2
votes

Your view is trying to render 'catalog/tareas.html'

return render(request, 'catalog/tareas.html', {...})

But your template name is catalog/Tareas.html.

If you are developing on a case-insensitive file system then you won't see any error in development.

However, in production, Heroku is running on a case-sensitive file system, so the template is not found.