WebFaction
Community site: login faq

Hi, I've developed a Django application locally using the built in Django web server along the way. The application consists of a single Django project containing a single Django application.

My issue is that I have some imports like this in, for instance, myapp/views.py:

from myapp import models

this works on my local setup and Django's development server.

I've set up all the various bits on my webfaction account to deploy the app but imports like the above have been failing with errors like 'no module myapp.models'.

Now, I can fix things by changing the imports to:

from myproject.myapp import models

but would prefer not to have to do this. I guess this behaviour is down to the WSGI pythonpath not containing 'myapp', just 'myproject', whereas the Django development server includes all the applications in a project in its module search path.

What I'd like to know is how to get Django running on webfaction to include myapp on its search path so I don't have to couple myapp to myproject. Is there some piece of setup that I may have overlooked or do I need to edit the WSGIPythonPath setting in httpd.conf to include each application? Or something else entirely!

Thanks in advance :)

asked 15 Dec '10, 07:26

zerog
4124
accept rate: 100%

edited 15 Dec '10, 07:28


You can add the path to your 'myproject' directory to the PYTHONPATH by adding it to your WSGIPythonPath line (as you said).

This is generally the simplest and easiest solution.

permanent link

answered 15 Dec '10, 07:53

David L ♦♦
1.4k13
accept rate: 45%

Hi, did you find a solution to that problem. It seems I have the same problem. I always get a No module named main.models error at this line: from main.models import * where "main" is my my app.

I added myapp path to WSGIPythonPath, but nothing changed. What am I doing wrong?

permanent link

answered 18 Dec '10, 04:38

xpanta
622544
accept rate: 0%

Could you open a support ticket so we can take a closer look?

(18 Dec '10, 04:43) David L ♦♦

Hi,

I had the same problem and got it solved. The problem is that at least in some cases (as it was for me), you have to add your app to your pythonpath yourself. There are several ways to do this. You can read about all of the different ways here: http://docs.webfaction.com/software/python.html#importerror

What I did was add the path to my app into the "myproject.wsgi" file:

  1. Open /home/username/webapps/djangoapp/myproject/myproject.wsgi
  2. If there is no line such as

sys.path = ['/home/username/webapps/djangoapp/myproject'] + sys.path

Add it in there.

You can add more paths of course as well, check out the documentation link for more info.

permanent link

answered 03 Jan '11, 06:22

Rrr8
16124
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×908
×15

question asked: 15 Dec '10, 07:26

question was seen: 8,254 times

last updated: 03 Jan '11, 06:22

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM