CGI != FastCGI != WSGI
If all they offer is CGI, the general consensus is that you ought
look elsewhere as (1) it's not supported in Django and (2) if it
was supported in Django, performance would be abysmal in an
off-the-charts sort of way. A new python process is started for
each request, all the code is hauled into memory for one request,
and then disposed of. Not bad for small sites with low-volume
traffic. But it easily gets swamped. A better alternative is
to have the python interpreter stick around with your code in
memory once and then pass requests to the existing code. Enter
FastCGI, WSGI and mod_python to solve this problem, each in its
own way.
Python does do CGI, FastCGI and WSGI as well as the obvious
mod_python. :)
Django/Python does FastCGI and WSGI as well as mod_python.
> And I don't even know if fastcgi is accessible for python. I come
> from a .Net/Java background and everything apache- and cgi-based is
> quite foreign to me.
Hopefully the above description helps clarify the "fastcgi !=
cgi" confusion here.
I don't know what GoDaddy offers in the package you are using.
If it's CGI, your outta luck. However, if they do offer FastCGI
or WSGI, you're in luck (nothing you mentioned sounded like they
offered mod_python).
-tim
With the economy class Linux hosting its a bit tricky. For starters you don't have root access to the site packages so you cannot install for example MySQL-Python.
1. Godaddy has virtualenv installed, so first, create a virtual environment venv: (I use $HOME/lib/ for all the installed stuff below)
cd ~/ mkdir lib cd lib virtualenv --no-site-packages venv
The python package folder is $HOME/lib/venv/lib/python2.7/site-packages
2. Install the latest Django through pip
pip install Django
3. Create a new project
django-admin.py startproject mysite
4. Change the database configuration in mysite/setting.py file. When setting the path for the database file, please use the absolute path:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '/var/chroot/home/content/11/10420811/lib/venv/mysite/mydatabase.db', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', } }
While in here there are a few other things to consider changing:
ADMINS =
can be updated with your infoINSTALLED_APPS
: 'django.contrib.admin',This will save you some setup later!
5. Set the Locale information in $HOME/.bash_profile
file, otherwise you cannot set the superuser when you sync the database. You can edit the file with vim:
export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8
6. Now run the script using the script command:
source ~/.bash_profile
7. If everything is setup properly, you should be able to sync the database:
python2.7 manage.py syncdb
You should see the admin tables get created and it will ask you to create a new user.
8. Now we setup the dispatch functionality so we can access the webpage without running server through Django using flup. So download and untar flup:
cd ~/lib/venv/lib/python2.7/site-packages wget http://pypi.python.org/packages/source/f/flup/flup-1.0.2.tar.gz#md5=24dad7edc5ada31dddd49456ee8d5254 tar -xvzf flup-1.0.2.tar.gz mv flup-1.0.2/flup/ .
9. In $HOME/html folder, create dispatch.py and add the following lines of code:
#!/usr/local/bin/python2.7 import sys, os sys.path += ['/your/home/path/lib/venv/lib/python2.7/site-packages'] sys.path += ['/your/home/path/lib/mysite/'] os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' from flup.server.fcgi import WSGIServer from django.core.handlers.wsgi import WSGIHandler WSGIServer(WSGIHandler()).run()
Also do a chmod +x dispatch.py
to make the python script executable!
10. In $HOME/html/.htaccess file, add the following codes:
AddHandler fcgid-script .fcgi Options +FollowSymLinks RewriteEngine On RewriteBase / # everything else sent to django RewriteRule ^(dispatch\.py/.*)$ - [L] RewriteRule ^(.*)$ dispatch.py/$1 [L]
Another good thing to note is that you can ReWrite URLS if you have current applications isntalled, ie.e dokuwiki.
#Add this above "everything else sent to django" #Below other folders with static content and PHP , etc.. #hosted at yourdomain/dokuwiki RewriteRule ^(dokuwiki/.*)$ - [L] #You can also create your "django" project at a different location rather than your domain root by changing the 2nd RewriteRule , i.e.: # everything else sent to django RewriteRule ^(dispatch\.py/.*)$ - [L] RewriteRule ^(djangoproj/.*)$ dispatch.py/$1 [L] #Make sure to create the djangoproj folder inside your html dir, cd html; mkdir djangproj #This becomes a bit annoying because your urlpatterns in url.py will now always have to include 'djangoproj' at the beginning.
11. Update your urls.py file to look like so:
from django.conf.urls import patterns, include, url from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}), url(r'^admin/', include(admin.site.urls)), )
This will ensure you can access the admin application, as well as the static root where all your img js and css are. Also note to copy the admin img/js/css from /django/contrib/admin/static
. Mine was in
~/lib/venv/lib/python2.7/site-packages/django/contrib/admin/
I used cp -r to copy it over to my application static dir/var/chroot/home/content/11/10420811/lib/venv/mysite/static/
cp -r ~/lib/venv/lib/python2.7/site-packages/django/contrib/admin/ ~/lib/venv/mysite/static/
12. That is it, you should have access to your site now! Access to http://your.website.com/adminshould work!
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
Gerald Klein DBA
Arch Awesome, Ranger & Vim the coding triple threat.
Linux registered user #548580
from django.core.handlers.wsgi import WSGIHandler WSGIServer(WSGIHandler()).run()
from yourapp import app WSGIServer(app).run()
AddHandler fcgid-script .py