Django is a popular framework for developing websites and web applications. In this tutorial we will tell you how you can install it on your hosting.
- Go to the Setup Python App menu item
- Click the Create Application button
- Enter the name of the directory where Django will be installed, starting with the domain folder. There is no need to put a slash at the beginning and at the end of the path. We recommend that you place the application in a folder with your domain name, on the same level as the public_html folder, but not inside it.
Do not fill in the fields: “Application launch file” and “Application entry point”.
Specify the path to the log file, note that part of the path is already prescribed. We recommend placing logs in the logs folder - After creating the application – go to it and copy the link to enter the virtual environment
- Go to the Directadmin home page and go to Web SSH Client. If you do not have this option – write a request to support to activate it. SSH access is granted only to clients who have been fully verified.
- In the SSH console, enter your login and password (the same as for Directadmin).
Enter the command to log in to the virtual environment that you copied earlier. For example, a command might look like this:
source /home/username/virtualenv/domains/example.com/django/3.8/bin/activate && cd /home/username/domains/example.com/django
To install Django, enter the command:
pip install django
To create a new Django project, enter the command:
django-admin startproject myapp ~/domains/example.com/django
Where myapp is the name of your application, example.com/django – the name of the domain and folder where you created the Python application. - Now you need to make settings in the file settings.py. For our example, it will be available in the ~/domains/example.com/django/myapp/settings.py folder
In this file, in the variable ALLOWED_HOSTS = [‘example.com’, ‘www.example.com’] – enter your domain, which should open the site. - Copy the contents of the wsgi.py file intopassenger_wsgi .py.
Forour example:
cp ~/domains/example.com/django/myapp/wsgi.py ~/domains/example.com/django/passenger_wsgi.py
- And the last step is to run the command in order to perform the migration:
python ~/domains/example.com/django/manage.py migrate
After that you can start configuring and populating your Django site