Django apache mod-python setup (vista) - django

I am trying to setup my development environment on my local vista machine (django+apache+mod-python+postgres) and for some reason I can't load the settings.
Everything works on the built-in server but not under apache.
Here is my httpd.conf
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE movies.settings
PythonOption django.root /movies
PythonDebug On
PythonPath "['C:/django'] + sys.path"
</Location>
And Error:
ImportError at /
No module named main.urls
Request Method: GET
Request URL: http://localhost/
Exception Type: ImportError
Exception Value:
No module named main.urls
Exception Location:
C:\Python25\lib\site-packages\django\utils\importlib.py in import_module, line 35
Python Executable: C:\Program Files (x86)\Apache Software
Foundation\Apache2.2\bin\httpd.exe
Python Version: 2.5.4
Python Path: ['C:/django', 'C:\\Windows\\system32\\python25.zip',
'C:\\Python25\\Lib', 'C:\\Python25\\DLLs', 'C:\\Python25\\Lib\\lib-tk', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\bin', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2/_externals']

Where does your code for your project reside? The parent of the folder that contains your project should be on the Python path. Assuming main is your project name, and it's in C:\django\projects\main\ you'd need to have c:\django\projects\ on your python path.
Either that, or main.urls should be movies.urls in your settings.py.

I know that you asked this question a couple of weeks ago, but if you're still looking for help, you might try ServerFault. If you have success, please report back here!

Related

Apache, Django and wsgi, No module named 'encodings'

I've looked through many stack overflow questions with the same issues, but none of them solved my issue. I'm trying to deploy Django on AWS - Ubuntu 18.04 using Apache and WSGI.
When running my website with Django's servers on port 8000, everything works fine. Then when I attempt to run on apache I get the following error in my logs.
Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
Command line: '/usr/sbin/apache2'
(2)No such file or directory: mod_wsgi: Unable to stat Python home /var/www/html/projects/venv
Python interpreter may not be able to be initialized correctly. Verify the supplied path
and access permissions for whole of the path.
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
As it says clearly mod_wsgi and Python 3 are configured. I am using a virtual environment. My project is located at:
/var/www/html/project/venv/mysite
My Apache conf file is configured as:
<Directory /var/www/html/projects/venv/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess mysite python-path=/var/www/html/projects/venv/mysite python-home =/var/www/html/projects/venv
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/html/projects/venv/mysite/mysite/wsgi.py
Alias /static /var/www/html/projects/venv/mysite/polls/static
<Directory /var/www/html/projects/venv/mysite/polls/static>
Require all granted
</Directory>
I'm not sure where to go from here. I don't fully understand what the error means. I have Python installed in my Venv. There is a file pyenv.conf which reads
home = /usr
implementation = CPython
version_info = 3.6.9.final.0
virtualenv = 20.0.20
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3
I'm wondering if this base-executable path being different than my python path in the apache config file is causing problems, but I'm not sure exactly what I need to do from here (or if this is even part of the problem. I believe permissions should not be the issue since I added all of my files within the var/www/html folder.
Update: I added the recommended permissions to all files in the chain and that didn't change anything.
Any advice is appreciated.

Django with Apache and mod_wsgi on Windows 2008 Server

I'm experiencing a problem with deploying a site with Apache 2.2, Django 1.5.4, Python 3.3.2 and mod_wsgi 3.4
Here is my train of thought.
After installing an Apache, I put "Hello world" index.html in htdocs directory to check if I set it up properly. No problem here.
Than I installed Python, Django (import django - no errors) and mod_wsgi.
To check on wsgi I did httpd.exe -e debug and got this in return:
...
[debug] mod_so.c(246): loaded module wsgi_module
Than I added following to httpd.conf:
WSGIScriptAlias / C:/Program Files (x86)/Apache2.2/htdocs/my_project/my_site/apache/django.wsgi
<Directory C:/Program Files (x86)/Apache2.2/htdocs/my_project/my_site/apache/>
Order deny,allow
Allow from all
</Directory>
At this point I can't start an Apache no more - The requested operation has failed!
And now httpd.exe -e debug returns Syntax error on line 496 of C:/Program Files (x86)/Apache2.2/conf/httpd.conf: Invalid option to WSGI alias definition.
Please, let me know if addition information required.
This is my first experience and your assistance is greatly appreciated.
When you have spaces in path names in the Apache configuration, they must be quoted.
WSGIScriptAlias / "C:/Program Files (x86)/Apache2.2/htdocs/my_project/my_site/apache/django.wsgi"
<Directory "C:/Program Files (x86)/Apache2.2/htdocs/my_project/my_site/apache/">
Order deny,allow
Allow from all
</Directory>

Django ImportError: Could not import settings 'settings' - No module named csrf

I am just starting to fiddle around with django. First I made a small app on my windows machine and verified it worked fine
Then, I zipped the entire project, and opened the zip on a linux machine.
The linux machine was installed with mod_wsgi and django 1.1.1, of course.
I created the following dirs:
/usr/local/bin/ROOT - contains only one file, django.wsgi
/usr/local/bin/ROOT/myapp - root dir of django app
Per the instructions here, I added to httpd.conf:
<VirtualHost *:80>
ServerName server
ServerAlias server
ServerAdmin webmaster#example.com
WSGIScriptAlias /myapp /usr/local/bin/ROOT/django.wsgi
<Directory /usr/local/bin/ROOT/>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now per the instructions here I put in /usr/local/bin/ROOT/django.wsgi:
import os
import sys
path = '/usr/local/bin/ROOT'
if path not in sys.path:
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
If it is of any importance: there is nothing set on PYTHOHPATH before the application starts.
After that I did a graceful restart to apache, and went to server/myapp. I got a 500 error.
Lookin in the log I see:
[Sun Dec 05 12:24:17 2010] [error] [client XXXX] ImproperlyConfigured: Error importing middleware django.middleware.csrf: "No module named csrf"
What am I doing wrong? all other threads I found about this always either end up with a conclusion that it's an old version of django (but mine's 1.1.1) or that there are several apps running, but I have only one...
Help?
"django.middleware.csrf" is the package in Django 1.2.x
For Django 1.1.x CSRF settings read the appropriate docs Here
The package in 1.1.x was "django.contrib.csrf.middleware.CsrfMiddleware"
1.1.1 is an old version of Django (the current version is 1.2.3), and that's almost certainly the cause of your problem. There is no django.middleware.csrf in 1.1.1.

Have problem with deploying django using apache

Hello I am having a problem with Django trying to get it deployed on a server using apache. for some reason when I write this information in my httpd.conf file.
<location "/mysite">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE mysite.settings
PythonOption django.root /mysite
PythonDebug off
PythonPath "['/user/local/src/djcode','/user/local/src/djcode/mysite'] + sys.path"
</Location>
I get this error when I restart apache.
Syntax error on line 3 of /etc/apache2/httpd.conf:
Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
Any ideas?
this error is pretty much self explanatory (second line is important to you):
Invalid command 'PythonHandler', perhaps misspelled
or defined by a module not included in the server configuration
PythonHandler is a command unknown by apache. it's a "module command" known by mod_python. so if missing it says invalid command (OR defined by module not in...).
so make sure mod_python is installed.
you might know it anyways, but just follow this document http://docs.djangoproject.com/en/dev/howto/deployment/modpython/
Also, i recommend you use mod_wsgi instead of mod_python. See deprecation warning on top of this page: http://docs.djangoproject.com/en/1.2/howto/deployment/modpython/
Support for mod_python will be
deprecated in a future release of
Django. If you are configuring a new
deployment, you are strongly
encouraged to consider using mod_wsgi
or any of the other supported
backends.
python_mod is not installed or not configured in httpd.conf.
If you have installed it, then add this line below in httpd.conf:
LoadModule python_module modules/mod_python.so

django site doesn't see urls.py

I just moved my site to an actual apache server (was developing locally before) and the site can't seem to find the urls.py file. basically what happens is that the homepage works, which is weird in itself considering that if i go to any url, e.g. website/about/, i will get a 404 error with text {'path': u'about/'}.
I tried ROOT_URLCONF set to mysite.urls and just urls, and if i move the urls.py it will continue to behave the same way.
I don't know if its related but I also can't seem to access my site media folder, it seems as though the server is still reading it in its old path, but the settings.py file is correct. (tried restarting apache, rebooting server, etc..)
I would be more worried about it not finding the media directory, that's pure apache. If that part of the equation isn't working, nothing else will. Work with apache's httpd.conf until you can browse to the media directory correctly first.
Update:
I copied in my working conf file and substituted your values. Your django.root might need to be "" or not set at all, as I've found that it shouldn't end with a /:
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE fikdusite.settings
PythonOption django.root ""
PythonDebug On
PythonPath "['/django_apps/', '/django_apps/fikdusite/'] + sys.path"
</Location>
And make sure that the .profile of the user that apache runs your site as, has:
export DJANGO_SETTINGS_MODULE='fikdusite.settings'
export PYTHONPATH=$PYTHONPATH:/django_apps:/django_apps/fikdusite
First, don't use mod_python, use mod_wsgi.
Secondly, don't forget that you need to restart Apache every time you make a code change in Django.