Can't run django on Apache

11 views
Skip to first unread message

John Maines

unread,
Mar 4, 2009, 2:47:01 PM3/4/09
to Django users
Hello:

I've installed Django 1.0 on Ubuntu and am trying to get it to run on
Apache. Apache is installed, working fine, with mod-python also in
place. I'm new at everything Linux.

But when I try to run my app (a test blog), Apache gives an
ImportError message (below) I have come across NUMEROUS references to
this error message, and the solution usually seems to involve changing
the Python Path. But nothing I try seems to work. I've tried using /
user/local for a path, /var/www; the path to my app. Nothing works.
Any suggestions?

MOD_PYTHON ERROR

ProcessId: 9980
Interpreter: 'mysite'

ServerName: 'ubuntu.ubuntu-domain'
DocumentRoot: '/var/www/'

URI: '/mysite'
Location: '/'
Directory: None
Filename: '/var/www/mysite'
PathInfo: ''

Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'

Traceback (most recent call last):

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1229, in _process_target
result = _execute_target(config, req, object, arg)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1128, in _execute_target
result = object(arg)

File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 228, in handler
return ModPythonHandler()(req)

File "/usr/lib/python2.5/site-packages/django/core/handlers/
modpython.py", line 191, in __call__
self.load_middleware()

File "/usr/lib/python2.5/site-packages/django/core/handlers/
base.py", line 31, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:

File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 28, in __getattr__
self._import_settings()

File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 59, in _import_settings
self._target = Settings(settings_module)

File "/usr/lib/python2.5/site-packages/django/conf/__init__.py",
line 94, in __init__
raise ImportError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE,
e)

ImportError: Could not import settings 'settings' (Is it on sys.path?
Does it have syntax errors?): No module named settings

xankya

unread,
Mar 4, 2009, 4:28:16 PM3/4/09
to Django users
I guess u need to set python path to mysite plus django folders

In httpd.conf:

<Location "/mysite">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE settings
PythonDebug On
PythonPath "['path to mysite', 'path to django'] + sys.path"
</Location>

Maines, John

unread,
Mar 4, 2009, 4:31:02 PM3/4/09
to django...@googlegroups.com

Thanks. That's one of the about 50 variables I have tried with the path settings ... still no luck.

-- John

Danny Brown

unread,
Mar 4, 2009, 4:38:41 PM3/4/09
to django...@googlegroups.com
try above but change /mysite to /mysite/ and settings to mysite/settings

xankya

unread,
Mar 6, 2009, 6:32:57 PM3/6/09
to Django users
One thing I noticed in my windows and sun solaris is that, there is no
trailing slash in python paths. When I added trailing slash, apache
showed error. So you might as well try removing trailing slash in
python paths.

jai

unread,
Mar 10, 2009, 2:38:31 AM3/10/09
to Django users
just put this line in (/etc/apache2/sites-enabled/000-default)

<Location "/mysite/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonInterpreter mysite
PythonDebug On
PythonPath "['path to django','path to mysite'] +
sys.path"
</Location>

It should work fine.

Jana Álvarez Muñiz

unread,
Mar 10, 2009, 8:59:12 AM3/10/09
to django...@googlegroups.com
Hello!

I want to use translation in Django forms (and ModelForms), but the only solution I've found is using the 'label' attribute in the form fields
('from django.utils.translation import ugettext as _' is omitted):

forms.py:
class MyForm(ModelForm):
name = forms.CharField(label=_('Name'))
description = forms.CharField(label=_("Description"))
class Meta:
model = models.MyModel
fields = ('name', 'description')

models.py:
class MyModel (models.Model):
name = models.CharField(max_length=50,verbose_name=_("Name"))
description = models.CharField(max_length=200, verbose_name=_("Description"))

In ticket #3600 (http://code.djangoproject.com/ticket/3600) tells us that label only can be translated with 'gettext' during initialization, and this happens to me too.

Can somebody help me? I think must exist a way to translate fields form for a model...

Thanks!

Ramiro Morales

unread,
Mar 10, 2009, 9:15:03 AM3/10/09
to django...@googlegroups.com
On Tue, Mar 10, 2009 at 10:59 AM, Jana Álvarez Muñiz
<jana.a...@fundacionctic.org> wrote:
>
> Hello!
>
> I want to use translation in Django forms (and ModelForms), but the only solution I've found is using the 'label' attribute in the form fields
> ('from django.utils.translation import ugettext as _' is omitted):

You need to use ugettext_lazy() instead of ugettext().

>
> forms.py:
> class MyForm(ModelForm):
>    name = forms.CharField(label=_('Name'))
>    description = forms.CharField(label=_("Description"))
>    class Meta:
>        model  = models.MyModel
>        fields = ('name', 'description')
>
> models.py:
> class MyModel (models.Model):
>    name = models.CharField(max_length=50,verbose_name=_("Name"))
>    description = models.CharField(max_length=200,              verbose_name=_("Description"))
>

--
Ramiro Morales
http://rmorales.net

Jana Álvarez Muñiz

unread,
Mar 10, 2009, 10:34:48 AM3/10/09
to django...@googlegroups.com


> On Tue, Mar 10, 2009 at 10:59 AM, Jana Álvarez Muñiz
> <jana.a...@fundacionctic.org> wrote:
> >
> > Hello!
> >
> > I want to use translation in Django forms (and ModelForms), but the only > > solution I've found is using the 'label' attribute in the form fields
> > ('from django.utils.translation import ugettext as _' is omitted):

> You need to use ugettext_lazy() instead of ugettext().

Thanks! But anyone knows if it exists a way to translate without putting each field twice?:

forms.py:
class MyForm(ModelForm):

# First:
name = forms.CharField(label=_('Name'))
description = forms.CharField(label=_("Description"))

class Meta:
model = models.MyModel

# Second:

Rex

unread,
Mar 14, 2009, 10:52:43 PM3/14/09
to Django users
On Mar 4, 12:47 pm, John Maines <jmai...@sun-sentinel.com> wrote:
> Hello:
>
> I've installed Django 1.0 on Ubuntu and am trying to get it to run on
> Apache. Apache is installed, working fine, with mod-python also in
> place. I'm new at everything Linux.
>
> But when I try to run my app (a test blog), Apache gives an
> ImportError message (below) I have come across NUMEROUS references to
> this error message, and the solution usually seems to involve changing
> the Python Path. But nothing I try seems to work. I've tried using /
> user/local for a path, /var/www; the path to my app. Nothing works.
> Any suggestions?
>
> MOD_PYTHON ERROR
>
> ProcessId:      9980
> Interpreter:    'mysite'
>
> ServerName:     'ubuntu.ubuntu-domain'
> DocumentRoot:   '/var/www/'
>
> URI:            '/mysite'
> Location:       '/'
> Directory:      None
> Filename:       '/var/www/mysite'
> PathInfo:       ''
>
> Phase:          'PythonHandler'
> Handler:        'django.core.handlers.modpython'
>
> Traceback (most recent call last):
>
[snip]
> ImportError: Could not import settings 'settings' (Is it on sys.path?
> Does it have syntax errors?): No module named settings

I'm having the same issue as the OP. Each time I go to mysite.com/
myapp, Apache seems to look for a file called /var/www/myapp, instead
of launching the Django project I attempt to specify in my <Location>
directive.

I have a project called "mturk". I want to run it on from mysite.com/
myapp. Based on the answers to the OP's questions, it seems like I
should be putting something like this in one of my configuration
files:

<Location "/myapp/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /home/rex/django/mturk
PythonDebug On
PythonPath "['/home/rex/django/mturk'] + sys.path"
</Location>

Some sources say this snippet should go in /etc/apache2/httpd.conf,
and some sources say it should go in /etc/apache2/sites-enabled/000-
default. Which should I go with? Also, I read somewhere that I should
change my DocumentRoot to the path to the Django project, but wouldn't
that expose my database and my Python source?

Thanks,

Rex

Malcolm Tredinnick

unread,
Mar 14, 2009, 11:31:12 PM3/14/09
to django...@googlegroups.com
On Sat, 2009-03-14 at 19:52 -0700, Rex wrote:
[...]

> <Location "/myapp/">
> SetHandler python-program
> PythonHandler django.core.handlers.modpython
> SetEnv DJANGO_SETTINGS_MODULE mysite.settings
> PythonOption django.root /home/rex/django/mturk

*sigh* Will people please stop *guessing* at what goes into the
django.root option? Don't use options you don't understand what they're
for and if you work out that a particular option is needed, understand
what it does before filling it in. :-(

The documentation is pretty clear on what it should contain:
http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration


> PythonDebug On
> PythonPath "['/home/rex/django/mturk'] + sys.path"
> </Location>
>
> Some sources say this snippet should go in /etc/apache2/httpd.conf,
> and some sources say it should go in /etc/apache2/sites-enabled/000-
> default. Which should I go with?

It depends on which distribution you're running. On Fedora, for example,
it goes in /etc/httpd/conf.d/ . So you'll need to provide some more
information.


> Also, I read somewhere that I should
> change my DocumentRoot to the path to the Django project, but wouldn't
> that expose my database and my Python source?

The Django documentation for installing with modpython is accurate and
complete, so use that as your reference (then using the Apache manual
and other places to understand the terms in there if you're not sure).
The above advice is not just bad, it's dangerous and stupid. So you're
right to be suspicious. There's simply no reason to do that.

Regards,
Malcolm

Rex

unread,
Mar 15, 2009, 4:54:25 PM3/15/09
to Django users


On Mar 14, 7:52 pm, Rex <rex.eastbou...@gmail.com> wrote:
> On Mar 4, 12:47 pm, John Maines <jmai...@sun-sentinel.com> wrote:
>
>
>
> > Hello:
>
> > I've installed Django 1.0 on Ubuntu and am trying to get it to run on
> >Apache.Apacheis installed, working fine, with mod-python also in
> > place. I'm new at everything Linux.
>
> > But when I try to run my app (a test blog),Apachegives an
> > ImportError message (below) I have come across NUMEROUS references to
> > this error message, and the solution usually seems to involve changing
> > the Python Path. But nothing I try seems to work. I've tried using /
> > user/local for a path, /var/www; the path to my app. Nothing works.
> > Any suggestions?
>
> > MOD_PYTHON ERROR
>
> > ProcessId:      9980
> > Interpreter:    'mysite'
>
> > ServerName:     'ubuntu.ubuntu-domain'
> > DocumentRoot:   '/var/www/'
>
> > URI:            '/mysite'
> > Location:       '/'
> > Directory:      None
> > Filename:       '/var/www/mysite'
> > PathInfo:       ''
>
> > Phase:          'PythonHandler'
> > Handler:        'django.core.handlers.modpython'
>
> > Traceback (most recent call last):
>
> [snip]
> > ImportError: Could not import settings 'settings' (Is it on sys.path?
> > Does it have syntax errors?): No module named settings
>
> I'm having the same issue as the OP. Each time I go to mysite.com/
> myapp,Apacheseems to look for a file called /var/www/myapp, instead
> of launching the Django project I attempt to specify in my <Location>
> directive.
>
> I have a project called "mturk". I want to run it on from mysite.com/
> myapp. Based on the answers to the OP's questions, it seems like I
> should be putting something like this in one of my configuration
> files:
>
> <Location "/myapp/">
>         SetHandler python-program
>         PythonHandler django.core.handlers.modpython
>         SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>         PythonOption django.root /home/rex/django/mturk
>         PythonDebug On
>         PythonPath "['/home/rex/django/mturk'] + sys.path"
> </Location>
>
> Some sources say this snippet should go in /etc/apache2/httpd.conf,
> and some sources say it should go in /etc/apache2/sites-enabled/000-
> default. Which should I go with? Also, I read somewhere that I should
> change my DocumentRoot to the path to the Django project, but wouldn't
> that expose my database and my Python source?
>
> Thanks,
>
> Rex

It turns out the problem was my PythonPath directive -- whereas I had
it set to contain the project directory, /home/rex/django/mturk, I
needed to set it to the parent directory, /home/rex/django. It works
now.

Bro

unread,
Mar 17, 2009, 12:59:57 PM3/17/09
to Django users
The result is :

<Location "/myapp/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /home/rex/django/mturk
PythonDebug On
PythonPath "['/home/rex/django/'] + sys.path"
</Location>

?

Bro

unread,
Mar 17, 2009, 1:54:54 PM3/17/09
to Django users
Hi

I've installed Django 1.02 on my dedibox. I'm trying to make .py file
readable and executable.
Apache, Python, Django are installed.
We have many website :
/var/www/mysite1
/var/www/mysite2
/var/www/mysite3

we have :
/var/django/mysite1
/var/django/mysite2

We configure in /etc/apache2/site-available/mysite1 :

----------
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mysite1.com
ServerAlias mysite1.com www.mysite1.fr mysite1.fr

DocumentRoot /var/www/mysite1/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/mysite/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>


<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite1.settings
PythonOption django.root /var/django/mysite1
PythonPath "['/var/django/', '/var/www'] + sys.path"
PythonDebug On
</Location>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error,
crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>
----------

But when we go in this url : mysite1.com
We get this error

------------
MOD_PYTHON ERROR

ProcessId: 14693
Interpreter: mysite.com'

ServerName: 'mysite.com'
DocumentRoot: '/var/www/mysite/'

URI: '/'
Location: '/'
Directory: None
Filename: '/var/www/mysite/'
PathInfo: ''

Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'

Traceback (most recent call last):

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1229, in _process_target
result = _execute_target(config, req, object, arg)

File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
1128, in _execute_target
result = object(arg)

File "/var/lib/python-support/python2.5/django/core/handlers/
modpython.py", line 228, in handler
return ModPythonHandler()(req)

File "/var/lib/python-support/python2.5/django/core/handlers/
modpython.py", line 191, in __call__
self.load_middleware()

File "/var/lib/python-support/python2.5/django/core/handlers/
base.py", line 44, in load_middleware
raise exceptions.ImproperlyConfigured, 'Middleware module "%s"
does not define a "%s" class' % (mw_module, mw_classname)

ImproperlyConfigured: Middleware module
"django.contrib.flatpages.middleware" does not define a
"FlatpageFallbackMiddlewar" class

Karen Tracey

unread,
Mar 17, 2009, 9:41:10 PM3/17/09
to django...@googlegroups.com
On Tue, Mar 17, 2009 at 1:54 PM, Bro <coolp...@gmail.com> wrote:

[snip]
 
File "/var/lib/python-support/python2.5/django/core/handlers/
base.py", line 44, in load_middleware
   raise exceptions.ImproperlyConfigured, 'Middleware module "%s"
does not define a "%s" class' % (mw_module, mw_classname)

ImproperlyConfigured: Middleware module
"django.contrib.flatpages.middleware" does not define a
"FlatpageFallbackMiddlewar" class

You seem to have dropped the e off the end of FlatpageFallbackMiddelware in your MIDDLEWARE_CLASSES setting that includes that middleware.

Karen

Graham Dumpleton

unread,
Mar 17, 2009, 9:59:48 PM3/17/09
to Django users
Either way, their dango.root setting is wrong as they are setting it
to physical file system path. Remove that whole django.root setting as
you do not need it when mounting at root of site.

The sooner people stop using mod_python the better. ;-)

Graham

On Mar 18, 12:41 pm, Karen Tracey <kmtra...@gmail.com> wrote:
Message has been deleted

Bro

unread,
Mar 18, 2009, 3:33:16 PM3/18/09
to Django users
What's the best way to do it ? I don't understand the official
tutorial
Reply all
Reply to author
Forward
0 new messages