On Dec 10, 10:01 pm, edward9 <edward...@gmail.com> wrote:
> Ok. Probably that its. But where can i found proper configuration for
> apache?

What do you mean by proper configuration? That is how Apache/
mod_python works, you can't readily change that behaviour.

If you want your Django instance to run as you rather than special
Apache user and want HOME to still be valid so you can avoid doing the
correct thing of using absolute paths rather than relying on $HOME
being set, then use Apache/mod_wsgi instead. In particular, use
mod_wsgi daemon mode and set up daemon process to run as you.

Do, disable mod_python completely, get mod_wsgi installed and work
through hello world examples in:

  http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

In the last one with daemon process, change WSGIDaemonProcess line to:

  WSGIDaemonProcess example.com user=your-user-name group=your-primary-
group \
    processes=2 threads=15 display-name=%{GROUP}

Replace 'your-user-name' and 'your-primary-group' with what you get
for user/group when you run 'id' command on command line. Eg. if:

  $ id
  uid=501(grahamd) gid=20(staff)

use:

  WSGIDaemonProcess example.com user=grahamd group=staff \
    processes=2 threads=15 display-name=%{GROUP}

Modify the hello world program to:

import os

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!\n'
    output += 'HOME=%s\n' % os.environ['HOME']

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

to verify that HOME is actually your home directory.

Once you have confirmed everything working as expect, then you can
instead set up Django.

For that see:

  http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Graham

> Or can U help me by pasting samples Apache configuration? I have read
> some tutorials about configuration Django with Apache and mod_python
> but nothing works :(
>
> And about quotas i think this is not it. Code without quotas works
> fine on dev server, but stop working on apache.
>
> Regards
> Ed
>
> On Dec 10, 10:14 am, Graham Dumpleton <graham.dumple...@gmail.com>
> wrote:
>
>
>
> > You do understand that when running under Apache that the code runs as
> > a special Apache user.
>
> > So, not only would the home directory not even be that for your home
> > account, Apache scrubs the HOME user environment variable from the
> > process environment anyway, and so trying to access HOME variable will
> > fail.
>
> > General rule in web programming is, never to rely on user environment
> > variables and secondly never rely on current working directory being a
> > particular location nor use relative paths, always use absolute paths
> > instead.
>
> > Graham
>
> > On Dec 10, 5:19 am, edward9 <edward...@gmail.com> wrote:
>
> > > Hello everybody
>
> > > I'm new and i want to say Hello to Everybody.
>
> > > I have problem with Apache. I install python, django, apache,
> > > mod_apache and all what is necessary.
>
> > > Apache configuration is:
> > >         <Location "/mysite/">
> > >             SetHandler python-program
> > >             PythonHandler django.core.handlers.modpython
> > >             SetEnv DJANGO_SETTINGS_MODULE mysite.settings
> > >             PythonOption django.root /mysite
> > >             PythonDebug Off
> > >             #PythonPath "['/',  '/mysite', '/var/www'] + sys.path"
> > >             PythonPath "['/'] + sys.path"
> > >         </Location>
>
> > > I created an application i root folder:
> > > django-admin.py startproject mysite
> > > and i started development(runserver). All works fine. "Configurations
> > > on your first Django-powered page". Running on apache also works fine.
>
> > > But when i create Django app:
> > > manage.py startapp inet
> > > views.py:
> > > # Create your views here.
> > > from django.http import HttpResponse
> > > from django.db import connection
> > > from django.conf import settings
> > > from datetime import datetime
>
> > > def main_page(request):
> > >         output = '''
> > >                 <html>
> > >                         <head><title>%s</title></head>
> > >                         <body>
> > >                                 <h1>%s</h1><p>%s</p><h2>%s</h2>
> > >                         </body>
> > >                 </html>
> > >         ''' % (
> > >                 '1','a','b','c'
> > >         )
> > >         return HttpResponse(output)
>
> > > urls.py
> > > from django.conf.urls.defaults import *
> > > from inet.views import *
>
> > > urlpatterns = patterns('',
> > >         (r'^$',main_page),
> > > )
>
> > > on development server works fine but started on apache i get:
>
> > > KeyError at /
>
> > > 'HOME'
>
> > > Request Method:         GET
> > > Request URL:    http://127.0.0.1/
> > > Exception Type:         KeyError
> > > Exception Value:
>
> > > 'HOME'
>
> > > Exception Location:     /usr/lib/python2.5/UserDict.py in __getitem__,
> > > line 22
> > > Python Executable:      /usr/bin/python
> > > Python Version:         2.5.4
> > > Python Path:    ['/', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-
> > > linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-
> > > dynload', '/usr/local/lib/python2.5/site-packages', '/usr/lib/
> > > python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/
> > > usr/lib/python2.5/site-packages/gst-0.10', '/usr/lib/pymodules/
> > > python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', '/usr/lib/
> > > pymodules/python2.5/gtk-2.0']
> > > Server time:    Wed, 9 Dec 2009 11:54:14 -0600
> > > Traceback Switch to copy-and-paste view
>
> > >     * /usr/lib/pymodules/python2.5/django/core/handlers/base.py in
> > > get_response
> > >         70.
> > >         71. # Get urlconf from request object, if available. Otherwise
> > > use default.
> > >         72. urlconf = getattr(request, "urlconf",
> > > settings.ROOT_URLCONF)
> > >         73.
> > >         74. resolver = urlresolvers.RegexURLResolver(r'^/', urlconf)
> > >         75. try:
> > >         76. callback, callback_args, callback_kwargs = resolver.resolve
> > > (
> > >         77. request.path_info) ...
> > >         78.
> > >         79. # Apply view middleware
> > >         80. for middleware_method in self._view_middleware:
> > >         81. response = middleware_method(request, callback,
> > > callback_args, callback_kwargs)
> > >         82. if response:
> > >         83. return response
> > >       ▶ Local vars
> > >       Variable  Value
> > >       exc_info
> > >       (<type 'exceptions.KeyError'>, KeyError('HOME',), <traceback
> > > object at 0x932c57c>)
>
> > > Can somebody help me? I dont have any ideas how to solve this problem.
>
> > > Thnask for help!
> > > Regards
> > > Edward9

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to