[PYTHON] How to deal with Django's Template Does Not Exist

TemplateDoesNotExist I got the above error when I ran the following code in Django.

views.py



from django.template.response import TemplateResponse


def product_list(request):
    return TemplateResponse(request, 'catalogue/product_list.html')

What should I do. There are two places to see in setting.py.

1. 1. Template path

Check if it looks like the following.

setting.py


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

If this happens, it's okay. This should be the default, so it should be okay if you haven't changed it.

2.INSTALLED_APPS This was the cause of my error.

setting.py


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ec.catalogue',
]

All applications in the project must be registered in INSTALLED_APPS. In other words, you also have to add the location that contains views.py and urls.py. Therefore, by adding the location where the application is stored (ec.catalogue in my case), Template can be used.

Recommended Posts

How to deal with Django's Template Does Not Exist
How to deal with imbalanced data
How to deal with imbalanced data
How to deal with DistributionNotFound errors
[systemd] How to deal with the problem that fancontrol does not work after suspending
How to use ManyToManyField with Django's Admin
How to deal with enum compatibility errors
[Python] How to deal with module errors
How to deal with memory leaks in matplotlib.pyplot
How to deal with errors when hitting pip ②
How to delete log with Docker, not to collect log
can't pickle annoy. How to deal with Annoy objects
How to deal with run-time errors in subprocess.call
How to deal with module'tensorflow' has no attribute'〇〇'
How to deal with SessionNotCreatedException when using Selenium
[AWS] Wordpress How to deal with "The response is not a correct JSON response"
How to deal with pyenv initialization failure in fish 3.1.0
[Python] How to deal with pandas read_html read error
What to do if sys / cdefs.h does not exist
How to deal with Executing transaction: failed in Anaconda
How to update with SQLAlchemy?
How to cast with Theano
How to Alter with SQLAlchemy?
How to use Django's GeoIp2
How to separate strings with','
How to RDP with Fedora31
2 ways to deal with SessionNotCreatedException
How to Delete with SQLAlchemy?
How to not load images when using PhantomJS with Selenium
[Linux] How to deal with garbled characters when viewing files
[AWS] How to deal with "Invalid codepoint" error in CloudSearch
A story about how to deal with the CORS problem
For beginners, how to deal with common errors in keras
How to deal with UnicodeDecodeError when executing google image download
How to create a new file when the specified file does not exist — write if the file exists
[VLC] How to deal with the problem that it is not in the foreground during playback
How to cancel RT with tweepy
How to deal with python installation error in pyenv (BUILD FAILED)
How to not escape Japanese when dealing with json in python
Python: How to use async with
How to deal with "You have multiple authentication backends configured ..." (Django)
How to change Django's SQLite3 uploaded to python anywhere with GUI only
How to use virtualenv with PowerShell
How to install python-pip with ubuntu20.04LTS
How to deal with errors when installing whitenoise and deploying to Heroku
How to install pandas on EC2 (How to deal with MemoryError and PermissionError)
How to get started with Scrapy
How to get started with Python
How to get started with Django
How to deal with errors when installing Python and pip with choco
How to Data Augmentation with PyTorch
How to use FTP with Python
How to calculate date with python
How to install mysql-connector with pip3
How to INNER JOIN with SQLAlchemy
How to install Anaconda with pyenv
How to authenticate with Django Part 2
How to authenticate with Django Part 3
[Tips] How to do template extends when creating HTML with django
What to do when you get angry that libxml / xmlversion.h does not exist when you put lxml with pip
How to deal with OAuth2 error when using Google APIs from Python