3👍
In your wsgi file you have:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'alex.settings'
which will search for settings.py
in /srv/www/alex/
.
That fails because, according to your posted tree, settings.py
is in /srv/www/alex/alex/
.
So you have 3 options:
- change the inserted path
- change the directory sturcture, or
- refactor
/srv/www/alex/
into a package containingalex.settings
.
2👍
You shouldn’t use sudo
with any commands that you need during development; because you don’t do development as root and it will lead to other problems down the road with permissions.
If you are new to django one of the first things that’s different about it than more traditional development frameworks (like PHP) is that you don’t need a web server or database server to get started. Django comes with everything you need during development, including a web server which you start with the runserver
command.
You should also use the official tutorial to get you started. Once you are comfortable with the tutorial then you will have a better understanding of how to deploy projects and can follow other posts easily.
Apache and mod_wsgi
is best when you are deploying projects, and not optimal (or necessary) during development.
I suggest you start with the following steps:
-
First, you should execute
sudo apt-get install python-virtualenv
, which will allow you to create a separate environment for your python/django work. This is the only command you should run as root, and it will only be done once. -
Now, to get started. Open a terminal and type in the following as your normal user:
$ virtualenv --no-site-packages django_project
This will create a new environment which you can use for your first project. Once that command has executed, type this:
$ source django_project/bin/activate
This activates the new virtual environment. You’ll notice your prompt now has
(django_project)
listed. This lets you know you are in the virtual environment. Finally, you should install django:(django_project) $ pip install django
Now that django is installed and you can start with the tutorial. In case you close your terminal (or open a new tab or terminal window), you can reactivate the virtual environment by executing source django_project/bin/activate
. You can get back to your normal shell by typing deactivate
in the virtual environment.
Hope that helps.
- [Django]-Django : CSRF verification failed even after adding {% csrf_token %}
- [Django]-Collectstatic command excluding nested directories and files
- [Django]-Django: Accessing Logged in User when specifying Generic View in urlpatterns
1👍
Can you post your wsgi.py? Maybe the problem is right there
My wsgi.py, maybe could help you.
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👍
I followed the same tutorial and had the same problem, but found an SO and some wsgi docs that got me further down the track. The key was adding 2 paths to the wsgi file search path list, though only one will actually point to the right settings.py
, depending on your file structure after shuffling things around per other advice, …
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 serve up fine now… minus the css and other static/media files. But that should be easy to fix with a bit more digging.