PyCharm 2018.3.2 reads Django's 'APP_DIRS' setting in TEMPLATES wrong, causing really bizarre behavior

I've been fighting with PyCharm for the last several weeks, trying to figure out why it was refusing to detect my apps' templates folders. It had worked in the past, but things changed recently (Perhaps with 2018.3? I'm not certain). Now, if APP_DIRS is set to anything except True in the initial definition of the Django TEMPLATES setting, PyCharm can't find my templates folders. Even setting it to True after the TEMPLATES = ['stuff'] line in doesn't fix the folder finding, which is really bizarre.

Here's a screenshot showing the folder detection actually working. Note that APP_DIRS is set to True in the definition of TEMPLATES:

Unfortunately, I can't use APP_DIRS = True in production, because it's slow and uncached. We use Django's cached template loader, like in this screenshot, which breaks the folder detection:

I've also tried using the uncached loader, but that's equally ineffective.

The REALLY weird thing is that setting APP_DIRS = False in the definition of TEMPLATES, and then setting it to True in the next line of still breaks the folder detection!

WTF?? How is that even possible? Is PyCharm, like, parsing the contents of to look for TEMPLATES = [ ... 'APP_DIRS': True ... ] or something?? I mean, it can't really be that, either, since I defined TEMPLATES in, which is imported by So what the heck is going on??

Please help me figure this out, as my brain is totally melted after all this frustration.



I've tried to reproduce your issue, but unfortunately I couldn't. I've changed APP_DIRS to a specific path instead of True, but PyCham still shows my template dirs in the structure list.

Can you provide example of the whole TEMPLATES object from your Alternatively, if you could reproduce the issue with a test project and attach this project here, that would be most helpful.


APP_DIRS is just a boolean, so "setting it to a different path" wouldn't have had any effect, because a string is a truthy value. Perhaps you're confusing APP_DIRS with DIRS?

The TEMPLATES object in my is fully visible in the bottom of each of the screenshots I provided. I made sure to make it visible to show exactly what its value was in each behavior case.


I've created a barebones Django project in a PyCharm project that reproduces the bug:

To create this repo, I started a new, empty PyCharm project, then inside that project I used the instructions at to create a fresh, default Django project (test_project) with a single default app (test_app). I then added a view function in test_app/, and a template, test_app/templates/test_app/index.html.

At this point, PyCharm correctly detected the templates folder. I could Cmd-click on 'test_app/index.html' on Line 5 of test_app/, and PyCharm would open index.html.

I then edited test_project/ to change the initial definition of TEMPLATES so that APP_DIRS is False, then added another line after the definition of TEMPLATES that sets APP_DIRS back to True.

At this point, PyCharm could no longer detect my templates folder, and it showed an error about not being able to find 'test_app/index.html' when editing test_app/

I hope this is enough to help you track down and fix this bug. It is very annoying. If you need anything else, please let me know.


I can confirm this behavior - setting APP_DIRS using constructs like "TEMPLATES[0]['APP_DIRS'] = True" doesn't work, but if you re-define the whole TEMPLATES object like this (see the following snippet it works again.

This maybe related to specific ways PyCharm parses Django settings, but normally this shouldn't be a problem. Is there a reason why you want to define APP_DIRS more than once ? You've mentioned that you're using cached templates loader due to performance issue, but how is this related to setting APP_DIRS more than once?

I'm trying to understand your use case to see if it warrants any fixes on our side. 


Heh, I wrote up this big, complex reply that explained a bunch of things about why I had to define TEMPLATES in the way I did. But in order to do due diligence, I also double-checked the Django template system docs to confirm something... only to realize that I'd been doing my TEMPLATES settings in a dumb way this whole time. lol

It turns out that it's totally possible to define APP_DIRS as True, and leave it set to True, while still enabling template caching. As long as TEMPLATES['OPTIONS']['debug'] = False, Django will perform template caching for you.

Once I set up my code to set 'debug' to False in production, and True in development (to disable caching while we're actually editing templates), I was able to leave APP_DIRS = True, which means PyCharm can successfully detect my template folders!

So, I no longer have a do-or-die issue with PyCharm's template folder detection. However, I do think PyCharm's mechanism for determining where to look for templates needs some work, due to that odd behavior we both confirmed in regards to how it reads APP_DIRS. But since the problem really only pops up when you're messing with the 'loaders' setting, which the vast majority of django projects don't actually need to mess with, this issue with PyCharm is not a high priority.


Glad to hear it's working for you. Thanks for the additional research done on your part.

The algorithm used for reading the settings might be just not accounting for some non-standard use cases, or workarounds implemented by users. To help developers come up with the best solution, we need a valid real-life case. We will definitely keep this issue in mind and gather more feedback from other users for further analysis to improve the overall integration with Django.

If you'll have any other issues in the future, don't hesitate to contact JetBrains support team.


Please sign in to leave a comment.