I've got an installation of xampp Apache 2.2 and mod_python 3.2.10 and
Python 2.5. Running on Windows 2003 server.
I have mod_python working fine in apache - I can view the contents of a
simple python file (mptest from mod_python testing).
I installed Django - I did this from the latest files via Subversion,
because the install file on Official version failed several times (the
note said Python 2.5 may cause problems)
I've added details of my project file in a location statement to
httpd.conf.
However, when I open the project in the browser:
http://localhost:8888/myproject/
I get the following error(s) displayed in the browser:
-----------------------------------------------
Mod_python error: "PythonHandler django.core.handlers.modpython"
Traceback (most recent call last):
File "D:\Python25\Lib\site-packages\mod_python\apache.py", line 299,
in HandlerDispatch
result = object(req)
File
"D:\Python25\lib\site-packages\django\core\handlers\modpython.py", line
177, in handler
return ModPythonHandler()(req)
File
"D:\Python25\lib\site-packages\django\core\handlers\modpython.py", line
145, in __call__
self.load_middleware()
File "D:\Python25\lib\site-packages\django\core\handlers\base.py",
line 22, in load_middleware
for middleware_path in settings.MIDDLEWARE_CLASSES:
File "D:\Python25\lib\site-packages\django\conf\__init__.py", line
27, in __getattr__
self._import_settings()
File "D:\Python25\lib\site-packages\django\conf\__init__.py", line
54, in _import_settings
self._target = Settings(settings_module)
File "D:\Python25\lib\site-packages\django\conf\__init__.py", line
82, in __init__
raise EnvironmentError, "Could not import settings '%s' (Is it on
sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
EnvironmentError: Could not import settings 'myproject.settings' (Is it
on sys.path? Does it have syntax errors?): No module named
myproject.settings
------------------------------------------
My httpd.conf file has the following settings at the end:
--
<Directory "d:/program files/xampp/htdocs/test">
AllowOverride FIleinfo
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On
</Directory>
<Location "/,yproject/">
SetHandler python-program
PythonPath "['d:/program files/xampp/htdocs/myproject'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.settings
PythonDebug On
</Location>
--
I've checked the "import django" from the python command line and there
were no errors, so I believe it's installed and accessible.
I've tried manually adding to sys.path the directories of the django
installation and my project with no effect. I'm wondering whether by
manually installing the django files from subversion I missed some key
settings, but I've not found any notes to allow me to check.
Can anyone give me any pointers for resolving this behaviour?
> Can anyone give me any pointers for resolving this behaviour?
>
I think you want this:
PythonPath "['d:/program files/xampp/htdocs/'] + sys.path"
(I don't think this has anything to do with Py2.5, etc. It's just
python path issues. :)
> PythonPath "['d:/program files/xampp/htdocs/myproject'] + sys.path"
Try : PythonPath "['d:/program files/xampp/htdocs/'] + sys.path"
Nicolas
Actually, you may want to include both lines. That way,
`myproject.settings` will still work and you will be able to `import
myapp` instead of `import myproject.myapp` making your apps more
portable across projects.
--
----
Waylan Limberg
way...@gmail.com
PythonPath "['d:/program files/xampp/htdocs'] + sys.path"
to my httpd.conf overcame the issue with loading myproject module.
Simple when you know how.
Thanks again, Tim
I have C:\Program Files\xampp\htdocs as my default directory
Where should I place django?
I placed it in C:\Program Files\xampp\htdocs\python\
but can't get the 'import django' working properly... sadly i have to
use windows.
Thanks for the help.
B
Which django version/revision are you using?
> I have C:\Program Files\xampp\htdocs as my default directory
>
> Where should I place django?
Somewhere on the python path. :)
The usual approach is to either place it in site-packages or to place
a .pth file in site-packages, and then point the .pth to where ever
Django is.
Let's go the .pth route.
In the python terminal, do this:
import sys
print sys.path
That'll result in a list of directories, one of which is
"site-packages", probably something like this:
C:\python25\lib\site-packages\
In that directory, create a simple text file named <something>.pth
file. django.pth probably is sensible.
In the .pth file, place the path to wherever Django exists on your
filesystem. As an example, if you downloaded Django-0.95.tar.gz and
unzipped it into C:\Django-0.95\, then you'll want to put that in your
.pth
When python starts up, it starts with a simple sys.path, then adds
paths in the PYTHONPATH variable, plus any directories listed in .pth
files found on those paths.
When you code:
import django
what happens is, python looks for a package (that is, a .py file) or a
module (that is, a directory which contains an __init__.py file) named
"django" in any of the directories listed in sys.path, in order.
By adding django.pth to your site-packages directory (which is
included in the base sys.path list), you add C:\Django-0.95 (or
whatever dir you listed) to the sys.path list.
Then, when you run "import django", it finds the module "django"
within that dir.
The Python tutorial is surprisingly weak in this area, but if you
haven't read that, it's a good place to get started with Python.
http://docs.python.org/tut/tut.html
If you already know how to program, you'll also want to look at
http://diveintopython.org
Cheers,
Jeremy