[Django]-PyCharm code inspection complains template file not found, how to fix?

109👍

Just open the project view (view->tool windows -> project). There right-click on your templates-folder -> ‘mark directory as’-> Template directory

21👍

Try adding TEMPLATE_LOADERS to your settings file if you don’t have it. I think PyCharm looks for it and doesn’t load it from Django default settings. It solved my problem.

settings.py:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

5👍

If you have marked directory as template directory, but still get the warning, you can try changing the single quotes to double quotes

def home(request):
    return render_to_response('home.html')

change to this:

def home(request):
    return render_to_response("home.html")

Hope this helps.

👤Yier

3👍

I am using PyCharm 2018.2. You can follow the next steps to mark a directory as a template directory, so PyCharm will not give you warnings, and you will be able to go to the template by pressing cmd + B (Mac) or ctrl + B (Windows/Linux):

  1. Open the Settings dialog, and click the Project Structure page. You can use cmd + , (on macOS), or by choosing File | Settings (Windows/Linux)
    enter image description here

  2. Choose the directory to be marked as a template root.
    enter image description here

  3. Click on Templates on Mark as. In Mac you can also press alt+T.
    enter image description here

  4. Click on OK to apply the changes you made.

2👍

I had a similar issue that was cause by forgetting to include my app in settings.INSTALLED_APPS. Adding my app to the list cleared the inspection.

1👍

It’s fixed when I assigned “Django project root” from settings to project destination.

Leave a comment