Running the first Django project errors

My computer starts Ubuntu 12.04 and I followed this guide to get started with Django: http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on- ubuntu-10-04 /

I tried to run /srv/www/my project by alexrunning this commandsudo django-admin.py startproject alex

Then created apache folder and django.wsgifile ( /srv/www/alex/apache/django.wsgi)

tree for /srv/www/alex/

.
├── apache
│   └── django.wsgi
├── alex
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

2 directories, 6 files

Website alex apache:

<VirtualHost *:80>

    ServerName alex.djangoserver
    DocumentRoot /srv/www/alex

    <Directory /srv/www/alex>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIDaemonProcess alex.djangoserver processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup alex.djangoserver

    WSGIScriptAlias / /srv/www/alex/apache/django.wsgi

</VirtualHost>

The result of the apache error log:

[error] [client 127.0.0.1] mod_wsgi (pid=28076): Exception occurred processing WSGI script '/srv/www/floqq/alex/django.wsgi'.
[error] [client 127.0.0.1] Traceback (most recent call last):
[error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 219, in __call__
[error] [client 127.0.0.1]     self.load_middleware()
[error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 39, in load_middleware
[error] [client 127.0.0.1]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
[error] [client 127.0.0.1]     self._setup()
[error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
[error] [client 127.0.0.1]     self._wrapped = Settings(settings_module)
[error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 95, in __init__
[error] [client 127.0.0.1]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[error] [client 127.0.0.1] ImportError: Could not import settings 'alex.settings' (Is it on sys.path?): No module named alex.settings

UPDATE

apache / django.wsgi

import os
import sys

path = '/srv/www'
if path not in sys.path:
    sys.path.insert(0, '/srv/www')

os.environ['DJANGO_SETTINGS_MODULE'] = 'alex.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
+3
source share
4 answers

In your wsgi file you have:

sys.path.insert(0, '/srv/www')

os.environ['DJANGO_SETTINGS_MODULE'] = 'alex.settings'

who will search settings.pyin /srv/www/alex/.

This fails because, according to your published tree, settings.pyis in /srv/www/alex/alex/.

, 3 :

  • refactor /srv/www/alex/ , alex.settings.
+3

sudo , ; root, .

django, , , (, PHP), , - . Django , -, runserver.

, . , , , .

Apache mod_wsgi , ( ) .

:

  • sudo apt-get install python-virtualenv, python/django. , root, .

  • , . :

    $ virtualenv --no-site-packages django_project

    , . :

    $ source django_project/bin/activate

    . , (django_project). , . , django:

    (django_project) $ pip install django

, django , tutorial. ( ), , source django_project/bin/activate. , deactivate .

, .

+2

wsgi.py? , .

wsgi.py, , .

import os
import sys

sys.path.append('/Applications/MAMP/htdocs/Django-1.4')
sys.path.append('/Applications/MAMP/htdocs/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "meishi.settings")
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
+1
source

I followed the same tutorial and had the same problem, but found fooobar.com/questions/86963 / ... and a few wsgi docs that gave me the further way. The key added 2 paths to the list of wsgi file search paths, although only one of them will actually point to the right one settings.py, depending on your file structure after shuffling things around another tip, ...

base = os.path.dirname(os.path.dirname(__file__))
base_parent = os.path.dirname(base)
sys.path.append(base)
sys.path.append(base_parent)

My pages work fine now ... minus css and other static / multimedia files. But this should be easy to fix with a bit more digging.

+1
source

All Articles