How to set up Apache to serve up django websites?

71 views
Skip to first unread message

Roger Marcus

unread,
Oct 24, 2011, 2:39:29 AM10/24/11
to django...@googlegroups.com
I have the django project Mezzanine up and working well. They have done a much better job in making it easier for the user
to install and run their project.

I am now fighting to get this all working with apache.

From the django documentation, chapter 20, i have inserted:
<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE portal.settings
    PythonDebug On
</Location>
Into my apache default settings.
Once again, however, I have path problems. Assuming my portal is called portal, when I run another small python web service 
I get the following traceback error:

 File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/core/handlers/base.py", line 39, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()

  File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)

  File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/django/conf/__init__.py", line 89, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))

ImportError: Could not import settings 'portal.settings' (Is it on sys.path?): No module named portal.settings
I tried to add this to my apache envvars file as:
export PATH=/home/roger/projects/playground/feincms_env/bin:/home/roger/projects/portal:$PATH

Can someone help me resolve this final path problem? Thanks.
Roger

Andre Terra

unread,
Oct 24, 2011, 8:22:33 AM10/24/11
to django...@googlegroups.com

ImportError: Could not import settings 'portal.settings' (Is it on sys.path?): No module named portal.settings

I tried to add this to my apache envvars file as:


export PATH=/home/roger/projects/playground/feincms_env/bin:/home/roger/projects/portal:$PATH



You need to add /home/roger/projects to your path, so that portal.settings can get imported.



Cheers,
AT

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/bAnugUREnzQJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reikje

unread,
Oct 25, 2011, 5:16:59 AM10/25/11
to Django users
On a side note, I can recommend this book:
http://www.packtpub.com/django-1-1-testing-and-debugging/book
They have an entire chapter for running Django on Apache.

/Reik

Roger Marcus

unread,
Oct 25, 2011, 11:52:44 AM10/25/11
to Django users
Hi Reikje,

FANTASTIC TIP. The configuration in the book is straightforward and
clear.
It was not the 100% solution, but it took Apache out of the equation,
and the focus
was getting mod_wsgi configured and working.

Debugging tip:
the suggested script.wsgi is a great place to debug path issues.
In my case, the script worked using the virtual_env that Andreas
helped me with,
but did NOT work otherwise. By comparing the paths in the two
environments,
I was able to see what was needed to get it all up and running.

For the moment, there is an ugly sys.path = ['lots','of','paths'...],
based upon
=======
import sys
print sys.path
======
from the virtual environment.
Judging from the number of 'help! my code doesn't work under apache'
problems listed,
this is a standard problem like CLASSPATH is to java.

I will try to follow up with a summary of what is needed for other
travelers on this road.

thanks,

Roger Marcus


On Oct 25, 11:16 am, Reikje <reik.sch...@gmail.com> wrote:
> On a side note, I can recommend this book:http://www.packtpub.com/django-1-1-testing-and-debugging/book
> They have an entire chapter for running Django on Apache.
>
> /Reik
>
> On Oct 24, 8:39 am, Roger Marcus <roger.mar...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I have the django project Mezzanine up and working well. They have done a
> > much better job in making it easier for the user
> > to install and run their project.
>
> > I am now fighting to get this all working with apache.
>
> > From the django documentation, chapter 20, i have inserted:
>
> > <Location "/">
> >     SetHandler python-program
> >     PythonHandler django.core.handlers.modpython
> >     SetEnv DJANGO_SETTINGS_MODULE portal.settings
> >     PythonDebug On
> > </Location>
>
> > Into my apache default settings.
> > Once again, however, I have path problems. Assuming my portal is called
> > portal, when I run another small python web service
> > I get the following traceback error:
>
> >  File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj ango/core/handlers/base.py", line 39, in load_middleware
> >     for middleware_path in settings.MIDDLEWARE_CLASSES:
>
> >   File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj ango/utils/functional.py", line 276, in __getattr__
> >     self._setup()
>
> >   File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj ango/conf/__init__.py", line 42, in _setup
> >     self._wrapped = Settings(settings_module)
>
> >   File "/home/roger/projects/playground/feincms_env/lib/python2.6/site-packages/dj ango/conf/__init__.py", line 89, in __init__
> >     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
>
> > ImportError: Could not import settings 'portal.settings' (Is it on sys.path?): No module named portal.settings
>
> > I tried to add this to my apache envvars file as:
> > export
> > PATH=/home/roger/projects/playground/feincms_env/bin:/home/roger/projects/p ortal:$PATH
Reply all
Reply to author
Forward
0 new messages