Support Center » Knowledgebase » Programming and Scripting » How to set up Django on Quadra Hosting

How to set up Django on Quadra Hosting



You can run a Django application on Quadra Hosting's shared environment. At the time this article was written, we can support Python 3.4, 3.5, 3.6, etc along with the latest version of Django

  • To work with Python and Django, you should obtain shell access.
  • Setup virtualenv into your chosen directory and install Django into your own virtualenv. For example let's choose the name "venv" for this document and we'll create a virtual environment specific to your site called "yoursitename" inside this venv. So the venv directory will contain multiple virtual environments if you so desire, each living inside a subdirectory below venv. Adjust the paths accordingly if you are using a different name.  If you don't plan to have multiple virtual environments, you can simplify this path scheme.
    cd ~
    mkdir -p venv/yoursitename
    python3.6 -m venv venv/yoursitename
    source venv/yoursitename/bin/activate
    pip install django
    cd venv
    curl -L https://github.com/Kozea/flipflop/archive/1.0.tar.gz | tar xzf -
    cd flipflop-1.0
    python ./setup.py install
  • Setup / create your django application inside your domain / web site directory
  • Inside your Quadra Hosting control panel, go to Web Options and 
    • Turn off PHP
    • Turn on Error Log which will help you debug any problems / errors. The error log is located in ~/logs/DOMAINNAME.COM/error_log
  • Create a .htaccess file in your web site root directory containing the following code:
    Options +ExecCGI
    <IfModule fcgid_module>
    AddHandler fcgid-script .fcgi
    </IfModule>
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /path/to/django.fcgi/$1 [QSA,PT,L]
    
    You need to change /path/to/django.fcgi with the correct path, relative to your web site root directory.
  • Next, edit the django.fcgi file:
    #!/hsphere/local/home/acctname/venv/yoursitename/bin/python
    import os
    ####### Additional code begins
    import sys
    
    path = '/hsphere/local/home/acctname/path-to-your-app'
    if path not in sys.path:
        sys.path.append(path)
    ##### Additional code ends
    
    from django.core.wsgi import get_wsgi_application
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "XXXXX.settings")
    
    application = get_wsgi_application()
    
    from flipflop import WSGIServer
    WSGIServer(application).run()

Notes:

  • acctname is your quadra hosting account name / ftp login name
  • path-to-your-app is the path to your django application, usually located inside your web site directory, e.g. "domainname.com/xxx"


Article Details
Article ID: 227
Created On: 11 Feb 2016 02:48 AM
 Back
 Login [Lost Password] 
Email:
Password:
Remember Me:
Please note that the login and password to the support area is NOT the same as your hosting control panel login and password
 
 Search
 Article Options
Home | Register | Submit a Ticket | Knowledgebase | Downloads | Control Panel User's Guide | Server Status
Language: