Set PyCharm filepath for Django settings (to outside project folder)

Answered

I'm trying to set the location of my Django settings file in PyCharm. By opening Settings > Languages & Frameworks > Django, and editing the "Settings:" field, I try to enter the absolute path of the file. My settings file does NOT reside in the project directory. PyCharm seems to have a problem parsing the path.

My project directory is "C:\Dylan\NEMO\".

My settings file is located at "C:\Dylan\NEMO_runtime\settings.py". When I enter that path, it changes it to "_runtime\settings.py" and a warning that PyCharm "Can't find settings file _runtime\settings.py".

Is there a way to set the absolute path for the settings.py file that resides OUTSIDE the project directory?

 

2 comments

Hello.

settings.py (and everything else) should be in project directory to be supported by PyCharm

By the way, how do you use file outside of project directory? Do you add ``NEMO_runtime`` to PYTHONPATH?

0

Hi Ilya,

Yes, I set two environment variables for my runtime configuration:

PYTHONPATH=C:/Dylan/NEMO_runtime

DJANGO_SETTINGS_MODULE=settings

This works great when running the application. 

It's unfortunate that PyCharm requires the settings.py file to be inside the project directory. I think this requirement should be removed from PyCharm, because the official Django documentation allows the file to be anywhere.

I am researching how to package my Django application and prepare it to be open source. Other people will not have the same settings as me, so I think the reliable way to package it is not have a settings.py file in the version controlled source tree. Instead, the person deploying the application is required to create one, and tell Django where to find it with the environment variable. (If there's a better way to do it, I'd very much like to hear about it!)

I suppose I can create a symbolic link to fix the problem on my computer.

-- Dylan

0

Please sign in to leave a comment.