views:

334

answers:

1

Hi

I am new in apache, linux and python world. I am trying to deploy django application on apache using WSGI (the recommended way).

My django project directory structure is as follows...

  • /
  • /apache/django.wsgi
  • /apps/ #I put all my apps in this directory
  • /apps/providers/
  • /apps/shopping/
  • /apps/...
  • /middleware/
  • ...

In apache I have following settings....

LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / D:/Projects/project-name/apache/django.wsgi

<Directory "D:/Projects/project-name/apache/">
  Allow from all
  Order deny,allow
</Directory>

django.wsgi file has got following code...

import os
import sys
import settings

sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/..')

os.environ['DJANGO_SETTINGS_MODULE'] = 'project_name.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

On running I found this error in the appache's error.log...

  • Error occured on this line. from apps.providers.models import Provider
  • Import Error: No module named providers.models

I don't know why it is giving me this error. It should have loaded Provider from apps.providers.models but it is trying to load it from providers.model.

Any solution will be appreciated.

Thanks

A: 

Try this:

sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)),'..'))

It puts your project folder at the first position and it uses os.path.join to go one directory up (which might be better on windows).

It might be the case that there is another "apps" module on your python path.

stefanw
Thanks, it helped...
Software Enthusiastic