How can I Deploy Django App to CloudJiffy Cloud

 Django CMS is a free open-source content management system based on the Django web framework, which ensures a quick integration of the databases and new modules. Django CMS helps to simplify the process of creating complex websites due to its intuitive and easy-to-learn drag and drop interface. Simultaneously, it is powerful and expandable enough to satisfy the most demanding content editors.

Below, we’ll overview the steps required to automatically or manually install the Django CMS solution to the cloud.

Django CMS Automatic Installation

You can automatically get a preconfigured ready-to-work Django CMS instance up and running within minutes using our one-click installation widget:

The full list of applications, available for one-click installation, can be found at our Marketplace page or within the corresponding section at the dashboard.

As an alternative, you can deploy it manually with the help of the following step-by-step instruction, to take the complete control over the process. So, let’s see how to benefit on the provided at CloudJiffy Cloud Python hosting, implemented by means of the Apache + mod_wsgi bundle, on the example of Django CMS application hosting.

Create an Environment

First of all, let’s create an environment for Python applications hosting. To do this, follow the below steps:

1. Click the New environment button.

2. Navigate to the Python programming language tab, where the Apache application server will be selected automatically. State the resource limits, choose the region and enter the name (e.g. Django) for your environment.

  • You can also choose from the Python versions we provide by default: 2.7, 3.3, 3.4 or 3.5. While choosing, please take into consideration the compatibility of Django version you are going to use with the desirable Python version.
  • In case if going to deploy a large and highly visited application, it makes sense to add a separate DB node to your environment. Otherwise, you can use the default SQLite database, which will be located inside the application server container.

Finally, click Create at the bottom right corner of the frame.

3. Just in a minute, the environment will appear at the dashboard.

For now, you can proceed to the Django CMS application deployment: either create and deploy a new application or deploy the already existing one.

Build and Deploy Django CMS

1. For the new Django application to be set up, you need to access your Apache application server via the CloudJiffy SSH Gateway first.

Tip: In case you haven’t performed similar operations before, you need to:
  • generate an SSH keypair
  • add the public SSH key to the dashboard
  • establish the connection over SSH protocol

2. After entering the container that should create a virtual environment for your application inside. In such a way, you'll get an isolated Python environment and the ability to install packages without having the administrator privileges: Below command is used:

virtualenv virtenv

3. Activate and switch to the newly created virtual environment by executing the next command:

source virtenv/bin/activate

4. Now, let’s get and run the Django CMS installer script using the pip package manager with below command:

pip install djangocms-installer

Wait a minute for the operation to be completed.

5. Then, you need to delete the preinstalled by default application and create a new Django CMS app with below commands as shown in the fig:

rm -rf ROOT;
 
djangocms -w -p . ROOT -s

6. After executing the above mentioned command, you will see a set of questions, which will help to define the settings of the new application.

Let’s pay a special attention to the database configuration step:

  • In case you’ve added a separate DB node to the environment, specify the connection string to it, e.g for MySQL it will be mysql://mysql{node_id}-{env_name}.{hoster_domain}
  • If you prefer to work with the in-built SQLite database, define the desired location of the local DB file will be placed at through entering the path to it (e.g. set it to be stored alongside with other projects’ data within the ROOT directory: sqlite://localhost/ROOT/project.db)

Note- that Django version 1.7 and below is incompatible with Python 3.5, thus you should set it equal to 1.8 or higher in this case (or just use the stable one)

Complete the remaining wizard steps by entering the custom values or leaving the default ones (displayed at the end of strings in the square brackets).

7. When the application is configured, you’ll be asked to specify Username, Email and Password for the CMS administrator (superuser):

8. Next, enter the vim ROOT/wsgi.py command to edit the file with the mod_wsgi module entrypoint set. Replace this file content with the lines below:

import os,sys
virtenv = os.path.expanduser('~') + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
   if sys.version.split(' ')[0].split('.')[0] == '3':
       exec(compile(open(virtualenv, "rb").read(), virtualenv, 'exec'), dict(__file__=virtualenv))
   else:
       execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
   pass

sys.path.append(os.path.expanduser('~'))
sys.path.append(os.path.expanduser('~') + '/ROOT/')

os.environ['DJANGO_SETTINGS_MODULE'] = 'ROOT.settings'

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Save the made changes and exit the vim editor.

9. Then, create a symlink, that points to the file you’ve modified above, by executing the following line:

ln -sfT ~/ROOT/wsgi.py ~/ROOT/application

10. Finally, let’s link the static data. For that, perform the following steps:

  • enter the vim ROOT/settings.py command. In the opened file, find and adjust the values of the ALLOWED_HOSTSMEDIA_ROOT, STATIC_ROOT and STATICFILES_DIRS parameters:

    ALLOWED_HOSTS = ['*']
    MEDIA_ROOT = os.path.join(DATA_DIR, 'ROOT', 'media')
    STATIC_ROOT = os.path.join(DATA_DIR, 'ROOT', 'static')
    STATICFILES_DIRS = (     

                            os.path.join(BASE_DIR, 'ROOT', 'static_local'),
    )

     
    Note: ALLOWED_HOSTS can contain a list of strings representing the host/domain names that this Django site can serve. In the example, we use a value of '*' that will match any request’s Host header. However, you can specify a fully qualified name (not including port) or a value beginning with a period (e.g. .jelastic.com) as a subdomain wildcard.

    Save the changes and exit vim.

  • create new subdirectories for the static and media content:
  • mkdir ROOT/static_local 
  • mkdir ROOT/media    and, lastly, run the synchronization of resources with below command:
     
    ./manage.py collectstatic

    Enter yes if system asks for confirmation and wait till this process is over.

11. That’s all! Now, you can return to the dashboard and press Open in browser button next to your environment with Django CMS.

As a result, you will see the application administration panel.

For entering, use the superuser credentials you’ve specified while creating my Django CMS application.

Deploying Existing Django Application

In case it already have the previously built and packaged Django application, the deployment procedure can be performed just in a few steps, described below.

Note: Before proceeding further, please ensure the Django package contains the following files in its root:
  • requirements.txt file with the names of all the Python modules the application requires. This file will be read by deployment script in order to automatically install the listed modules with the help of the pip manager.
  • application file with the entry point script for running the application inside a virtual environment by means of Apache mod_wsgi (an example for Django apps can be seen here)

1. Upload the package with the Django application to the CloudJiffy dashboard via Deployment manager.

2. Press the Deploy to button and choose a necessary environment.

3. After the operation is finished, select the Open in browser button next to the environment.

4. That’s all! Now you can enjoy working with your Django application.

As you can see, it’s quite easy to deploy Django CMS and the appropriate Django-based applications with the CloudJiffy Python hosting. Nevertheless, in case you face any issues with this instruction, feel free to appeal for our technical experts’ assistance at StackOverflow.


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 14204