I'm trying to check if my host supports what is needed for my django site, so atm I'm trying to set up a basic django site. What makes this even more complicated is that I need to have another joomla page running from the same server (see below). I don't know if I'm doing something wrong (most probable) and what am I supposed to ask from the host. (I know I'm a little noob in this)
Here's what I have so far: in the /home/username/
library-site/ <-- django files
public-html/
library <-- virtual_env
(following a guide I've symlinked the site-packages of the virtualenv to library_site/lib)
I have to say that I've tried numerous guides so it's difficult to present the entire picture but here's what I have now
in public_html/library/dispatch.fcgi
#!/home/username/library/bin/python
import sys
import os
sys.path.insert(0, "/home/username/library/bin/python")
sys.path.append('/home/username/library/lib/python2.6/site-packages')
sys.path.insert(13, "/home/username/public_html/library")
open("/home/username/public_html/library/cgi.log", "w").write("Before try")
try:
os.environ['DJANGO_SETTINGS_MODULE'] = 'lib.settings'
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
except Exception:
open("/home/username/public_html/library/cgi.log", "w").write(format_exc())
raise
in public_html/library/.htaccess
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /library/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(dispatch\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]
Navigating like this to http://example.com/library displays the contents of the folder. Clicking on the dispatch.fcgi just displays the python code.
Running ./dispatch.fcgi from the returns the correct django output but the first four lines read
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
These all tell me that I need to ask something from the host but I have no idea what at this point.
Also, running
python ~/library_site/lib/manage.py runfcgi daemonize=false host=127.0.0.1 port=3033 maxrequests=1
as recommended here: https://twiki.cern.ch/twiki/bin/view/ITCF/DjangoGeneral does not return any problems.
Finally, starting the django server:
python manage.py runserver 0.0.0.0:8000
works fine. Can anyone please help?
FCGI requires a conversion layer between it and WSGI. Make sure you have flup installed and that your FCGI file is executable
Here is a guide I was able to get working some two years ago or so.
I now feel a little stupid as the answer was really trivial. Following this guide http://joemaller.com/1467/django-via-cgi-on-shared-hosting/ I've put the .fcgi in cgi-bin and wrote the appropriate .htaccess file in public_html and...Voila!
As a point of interest to anyone who tries this in the future, regarding the static files (which are even more of a pain), I've put them in 'public_html/library/static/' (<-- STATIC ROOT) using the absolute path and then my STATIC_URL was '/lib_files/static/'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.