reakh
reakh

Reputation: 111

django import (different directories) - best practice

I have a Django project under /var/www/django/my_proj and I need to import python modules from ~/my_folder.

What is the best practice of doing this?

Any way to do this through Django setting?

Upvotes: 0

Views: 984

Answers (2)

nabucosound
nabucosound

Reputation: 1293

If you are using virtualenvwrapper, just use add2virtualenv to add the path to your virtualenv_path_extensions.pth:

http://www.doughellmann.com/docs/virtualenvwrapper/command_ref.html#add2virtualenv

Upvotes: 0

Luke Sneeringer
Luke Sneeringer

Reputation: 9428

Add ~/my_folder to sys.path.

This isn't necessarily the cleanest way to do it, but the quick way is probably to do that in your settings.py file. settings.py is a Python script just like anything else, so:

import sys
sys.path.append('/home/yourname/my_folder/')

Note that this is only an acceptable solution until you deploy; once you deploy, presumably your modules will be elsewhere, and you'll want to do your sys.path modification in your mod_wsgi conf.

Upvotes: 1

Related Questions