How to start project on Django?

By default, the hosting accounts created on the server with support for PHP, Django needs to configure your account transferred to another server. This action is carried out by our specialists on request ticket. After the transfer of the hosting package on the Django server, you can start setting up the project.

Do you have a project on Django? For start, you must perform

  1. Createm folder domains/DOMAIN/django/VNAME
  2. Create file domains/DOMAIN/django/VNAME.wsgi, with content (replace variables DOMAIN, USERNAME and VNAME correct values):
import os,sys

apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)

sys.path.insert(0,'/home/USERNAME/domains/DOMAIN/django/VNAME/')
sys.path.insert(0,'/home/USERNAME/domains/DOMAIN/django/VNAME/VNAME/')
sys.path.insert(0,'/home/USERNAME/virtualenv/VNAME/')
sys.path.insert(0,'/home/USERNAME/domains/DOMAIN/django')
sys.path.insert(0,'/home/USERNAME/virtualenv/VNAME/lib/python2.7/site-packages')
os.environ['DJANGO_SETTINGS_MODULE'] = 'VNAME.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

For Django >= 1.7 you must replace this lines:

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

for this lines

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
  1. Download project to folder domains/DOMAIN/django/VNAME
  2. Write ticket to support with request to activate Django, at ticket add your Python and Django versions and VNAME, DOMAIN, USERNAME.

    If you need additional modules Python/Django - create file /home/USERNAME/domains/django/VNAME.requirements.txt at format PIP:

name==version
name

If not specified version of the module or version of Django, will be the installed latest version available at the time of installation. As default will be installed vesrion 2.7 Python.

If you need to create new (blank) project - you need Follow step 4

Recommendation!

After start Django project set at file domains/DOMAIN/django/VNAME/settings.py next parameters:

MEDIA_ROOT = '/home/USERNAME/domains/DOMAIN/public_html/media/'
STATIC_ROOT = '/home/USERNAME/domains/DOMAIN/public_html/static/'
MEDIA_URL = '/media/'
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/media/'

Description of variables:

VNAME=The project name. Must be unique.
DOMAIN=Your domain that connects to Django
USERNAME=User login. Used to access the control panel DirectAdmin

Reload project

For reload django-project you need add to file domains/DOMAIN/django/VNAME.wsgi strings:


# version 0.0.1
import rxmonitor

rxmonitor.start(interval=1.0)
rxmonitor.track(os.path.join(os.path.dirname(__file__), 'VNAME.wsgi'))

After changins content in file domains/DOMAIN/django/VNAME.wsgi (as example string version 0.0.1 changed to version 0.0.2) and reloading page, Django project will be reloaded.

> Dont forget set correct values DOMAIN and VNAME