views:

58

answers:

1

I'm trying to import sorl-thumbnail into my app in django. Now the way that i have the site set up, using mod_wsgi on centos5 with cpanel the path for the apps must have the project name when importing... which is a pain.

Obviously this is a cause of concern with portability of the app. I'm importing sorl-thumbnail, in previous apps i've just added sorl.thumbnail to the installed apps and it's worked.

However now it's causing issues unless i have the project name www. in front of the import path. It's never done this before and I can't seem to get around the path issue.

I've added www.sorl.thumbnail also but then the rest of the paths in the sorl files have errors. Any idea's on how to remedy this or fix a work around?

+3  A: 

You shouldn't need to use the project name when importing - just make sure that the apps are somewhere on your python path. Something along the lines of:

sys.path.append('/etc/django/domains/mydomain.com/myproject/')

... in your .wsgi file should do it (with the path to your own project, of course).

Ideally reusable apps should be outside of your project directory anyway, so consider creating a folder such as '/etc/django/lib/' to contain reusable apps and appending that to sys.path in your wsgi handler too.

Or, if you don't like that, perhaps use virtualenv and add your reusable apps directly to site-packages.

Or, if you don't like that, put your reusable apps somewhere else and symlink them to site-packages or somewhere on your python path.

In short, just make sure the package/module you're importing is on your python path. If you find yourself adding the project name or 'www' to a bunch of import paths, then you're probably doing something wrong.

ozan
very well explained and you have given great options for me to follow... very useful information too, so thanks very much for taking the time to write this.
Neil Hickman