{"id":7406,"date":"2022-04-18T09:24:07","date_gmt":"2022-04-18T09:24:07","guid":{"rendered":"https:\/\/chemicloud.com\/kb\/?post_type=ht_kb&#038;p=7406"},"modified":"2022-04-18T09:24:07","modified_gmt":"2022-04-18T09:24:07","slug":"install-and-setup-django-application","status":"publish","type":"ht_kb","link":"https:\/\/chemicloud.com\/kb\/article\/install-and-setup-django-application\/","title":{"rendered":"How to Install and Set up a Django Application"},"content":{"rendered":"<p>In this tutorial, you will learn to quickly install and set up a Django application with the cPanel graphical interface and from the command line.<\/p>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<p>You will need a general knowledge of programming concepts to go through this tutorial, and Python is recommended.<\/p>\n<p>You&#8217;ll also require a <span style=\"text-decoration: underline;\"><a href=\"https:\/\/chemicloud.com\/python-hosting\/#60b65e4e63b58\" target=\"_blank\" rel=\"noopener noreferrer\"><strong>Python Hosting<\/strong><\/a><\/span> plan. At ChemiCloud, we support the following python versions: 2.7.18, 3.3.7, 3.4.9, 3.5.9, 3.6.15, 3.7.12, 3.8.6, and 3.9.10.<\/p>\n<h2 id=\"how-to-set-up-python-application-in-cpanel\"><span id=\"how-to-set-up-a-django-application\">How to Set up a Django Application<\/span><\/h2>\n<h4 id=\"Step-1.3A-Create-a-Python-application-in-cPanel\"><span id=\"step-1-create-a-python-application-in-cpanel\">Step 1: Create a Python application in cPanel<\/span><\/h4>\n<p>The first step is to create a Python application within cPanel that will host the Django project. To do this, follow these steps:<\/p>\n<ol>\n<li>Log in to cPanel.<\/li>\n<li>In the\u00a0<strong>SOFTWARE<\/strong>\u00a0section of the cPanel home screen, click\u00a0<strong>Setup Python App<\/strong>:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3005\" src=\"https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python-300x93.png\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" srcset=\"https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python-300x93.png 300w, https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python-50x15.png 50w, https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python-60x19.png 60w, https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python-100x31.png 100w, https:\/\/chemicloud.com\/kb\/storage\/2020\/04\/Setup-Python.png 388w\" alt=\"Setup Python\" width=\"300\" height=\"93\" \/><\/li>\n<li>Click\u00a0<strong>CREATE APPLICATION<\/strong>:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2523\" src=\"https:\/\/chemicloud.com\/kb\/storage\/2019\/09\/Create-Application.png\" sizes=\"auto, (max-width: 276px) 100vw, 276px\" srcset=\"https:\/\/chemicloud.com\/kb\/storage\/2019\/09\/Create-Application.png 276w, https:\/\/chemicloud.com\/kb\/storage\/2019\/09\/Create-Application-50x11.png 50w, https:\/\/chemicloud.com\/kb\/storage\/2019\/09\/Create-Application-60x13.png 60w, https:\/\/chemicloud.com\/kb\/storage\/2019\/09\/Create-Application-100x22.png 100w\" alt=\"\" width=\"276\" height=\"60\" \/>The application form appears:<a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7407\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-783x401.png\" alt=\"\" width=\"643\" height=\"329\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-783x401.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-300x154.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-768x394.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-50x26.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-1536x787.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-2048x1050.png 2048w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-60x31.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Create-Python-Application-100x51.png 100w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<li>In the\u00a0<strong>Python version<\/strong> list box, select the Python version you&#8217;d like to use for your app. In our example, we&#8217;ll use Python <strong>version 3.8.6<\/strong>.<\/li>\n<li>In the\u00a0<strong>Application root<\/strong>\u00a0text box, type\u00a0<span class=\"user-input\">myapp<\/span>.<\/li>\n<li>In the\u00a0<strong>Application URL<\/strong>\u00a0list box, select the domain. Leave the rest of the URL blank.<\/li>\n<li>Leave\u00a0the\u00a0<span class=\"textbox\">Application startup file<\/span>\u00a0text box and\u00a0<span class=\"textbox\">Application Entry point<\/span>\u00a0text box blank.\n<div class=\"note msg-box\">    \t\t<div class=\"hts-messages hts-messages--info   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tWhen these text boxes are blank, cPanel automatically creates a\u00a0<em>passenger_wsgi.py<\/em>\u00a0startup file and\u00a0default\u00a0<strong>application<\/strong> object for you.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/div>\n<\/li>\n<li>Click <strong>CREATE<br \/>\n<\/strong>cPanel creates the application and sets up the Python environment in the top right corner of the page.<\/li>\n<li>At the top of the page, next to\u00a0<strong>Enter to the virtual environment. To enter the virtual environment, run the command<\/strong>\u00a0and copy the command. You will need this information in the following procedure.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-7413 size-full\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment.png\" alt=\"\" width=\"2504\" height=\"562\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment.png 2504w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-300x67.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-783x176.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-768x172.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-50x11.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-1536x345.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-2048x460.png 2048w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-60x13.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-Virtual-Environment-100x22.png 100w\" sizes=\"auto, (max-width: 2504px) 100vw, 2504px\" \/><\/a><\/p>\n<h4 id=\"Step-2.3A-Configure-the-Django-project\"><span id=\"step-2-configure-the-django-project\">Step 2: Configure the Django project<\/span><\/h4>\n<p>After you create the Python application in cPanel, you are ready to do the following tasks at the command line:<\/p>\n<ul>\n<li>Install Django.<\/li>\n<li>Create and configure the Django project.<\/li>\n<li>Configure Passenger to work with the Django project.<\/li>\n<\/ul>\n<p>To do this, follow these steps:<\/p>\n<ol>\n<li>Log in to your account\u00a0<a href=\"https:\/\/chemicloud.com\/kb\/article\/log-account-via-ssh\/\" target=\"_blank\" rel=\"noopener\">using SSH Client<\/a>. Or use your cPanel&#8217;s Terminal feature.<\/li>\n<li>Activate the virtual environment using the command you noted in step 9 above ^. For example:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">source \/home\/<span class=\"variable\">username<\/span>\/virtualenv\/myapp\/3.8\/bin\/activate &amp;&amp; cd \/home\/<span class=\"variable\">username<\/span>\/myapp\r\n<\/pre>\n<\/div>\n<div class=\"important msg-box\">    \t\t<div class=\"hts-messages hts-messages--alert   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tThe command prompt now starts with\u00a0<strong>(myapp:3.8)<\/strong>\u00a0to indicate that you are working in the\u00a0<em>myapp<\/em>\u00a0virtual environment with Python 3.8. All of the following commands in this article assume that you are working in the Python virtual environment. If you log out of your SSH session (or deactivate the virtual environment by using the\u00a0<strong>deactivate<\/strong> command), ensure you reactivate the virtual environment before following any steps below.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t<\/div>\n<\/li>\n<li>To install Django, type the following commands:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">cd ~; pip install django==2.1.8<\/pre>\n<\/div>\n<div class=\"tip msg-box\">\n<p><a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7414\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-783x206.png\" alt=\"\" width=\"643\" height=\"169\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-783x206.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-300x79.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-768x202.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-50x13.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-1536x404.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-60x16.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1-100x26.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/django-install-1.png 1580w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/p>\n<p>To verify the version of Django that is installed, type the following command:<\/p>\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">django-admin --version<\/pre>\n<\/div>\n<\/div>\n<\/li>\n<li>To create a Django project, type the following command:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">django-admin startproject myapp ~\/myapp\r\n<\/pre>\n<\/div>\n<\/li>\n<li>To create directories for the static project files, type the following commands:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">mkdir -p ~\/myapp\/templates\/static_pages\r\nmkdir ~\/myapp\/static_files\r\nmkdir ~\/myapp\/static_media\r\n<\/pre>\n<\/div>\n<\/li>\n<li>Use a <strong><a href=\"https:\/\/chemicloud.com\/kb\/article\/how-to-edit-a-file-using-cpanels-file-manager\/\" target=\"_blank\" rel=\"noopener\">text editor<\/a> <\/strong>to open the\u00a0<em>~\/myapp\/myapp\/<strong>settings.py<\/strong><\/em>\u00a0file, and then make the following changes:\n<ul>\n<li>Locate the\u00a0<strong>ALLOWED_HOSTS<\/strong>\u00a0line, and then modify it as follows. Replace\u00a0<span class=\"variable\"><em>example.com<\/em><\/span> with your domain name:\n<pre class=\"code\">ALLOWED_HOSTS = ['<span class=\"variable\"><em>example.com<\/em><\/span>']<\/pre>\n<p>In our example, we&#8217;ve used django.cchostingdemos.com<br \/>\n<a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts.png\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7415\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-783x135.png\" alt=\"\" width=\"643\" height=\"111\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-783x135.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-300x52.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-768x132.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-50x9.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-60x10.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts-100x17.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Allowed_hosts.png 942w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<li>Locate the\u00a0<strong>TEMPLATES<\/strong>\u00a0block, and then modify it as follows:\n<pre class=\"code\">TEMPLATES = [\r\n    {\r\n        'BACKEND': 'django.template.backends.django.DjangoTemplates',\r\n        'DIRS': [os.path.join(BASE_DIR,'templates')],\r\n        'APP_DIRS': True,\r\n        'OPTIONS': {\r\n            'context_processors': [\r\n                'django.template.context_processors.debug',\r\n                'django.template.context_processors.request',\r\n                'django.contrib.auth.context_processors.auth',\r\n                'django.contrib.messages.context_processors.messages',\r\n            ],\r\n        },\r\n    },\r\n]\r\n<\/pre>\n<p><a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7417\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-783x370.png\" alt=\"\" width=\"643\" height=\"304\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-783x370.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-300x142.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-768x362.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-50x24.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-60x28.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates-100x47.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-Templates.png 1462w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a>Once you&#8217;ve finished editing the <em><strong>settings.py<\/strong><\/em> file, please Save the changes.<\/li>\n<li>Locate the\u00a0<strong>STATIC_URL<\/strong>\u00a0line, and then add the following lines beneath it:\n<pre class=\"code\">STATIC_URL = '\/static\/'\r\nSTATIC_ROOT = os.path.join(BASE_DIR, 'static_files')\r\n\r\nMEDIA_URL = '\/media\/'\r\nMEDIA_ROOT = os.path.join(BASE_DIR, \"static_media\")\r\n<\/pre>\n<p><a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7418\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-783x314.png\" alt=\"\" width=\"643\" height=\"258\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-783x314.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-300x120.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-768x308.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-50x20.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-60x24.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files-100x40.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Django-static-files.png 1232w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Use a text editor to open the\u00a0<em>~\/myapp\/myapp\/urls.py<\/em>\u00a0file. Delete all of the existing text, and then copy the following text into the file:\n<pre class=\"code\">from django.contrib import admin\r\nfrom django.urls import path, include\r\nfrom django.conf import settings\r\nfrom django.conf.urls.static import static\r\nfrom django.conf.urls import url\r\nfrom django.views.generic.base import TemplateView\r\n\r\nurlpatterns = [\r\n    path('admin\/', admin.site.urls),\r\n    url(r'^$', TemplateView.as_view(template_name='static_pages\/index.html'), name='home'),\r\n] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\r\n\r\nurlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)\r\n<\/pre>\n<\/li>\n<li>Use a text editor to open the\u00a0<em>~\/myapp\/passenger_wsgi.py<\/em>\u00a0file. Delete all of the existing text, and then copy the following text into the file:\n<pre class=\"code\">import os\r\nimport sys\r\n\r\nimport django.core.handlers.wsgi\r\nfrom django.core.wsgi import get_wsgi_application\r\n\r\n# Set up paths and environment variables\r\nsys.path.append(os.getcwd())\r\nos.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'\r\n\r\n# Set script name for the PATH_INFO fix below\r\nSCRIPT_NAME = os.getcwd()\r\n\r\nclass PassengerPathInfoFix(object):\r\n\u00a0 \u00a0 \"\"\"\r\n\u00a0 \u00a0 \u00a0 \u00a0 Sets PATH_INFO from REQUEST_URI because Passenger doesn't provide it.\r\n\u00a0 \u00a0 \"\"\"\r\n\u00a0 \u00a0 def __init__(self, app):\r\n\u00a0 \u00a0 \u00a0 \u00a0 self.app = app\r\n\r\n\u00a0 \u00a0 def __call__(self, environ, start_response):\r\n\u00a0 \u00a0 \u00a0 \u00a0 from urllib.parse import unquote\r\n\u00a0 \u00a0 \u00a0 \u00a0 environ['SCRIPT_NAME'] = SCRIPT_NAME\r\n\u00a0 \u00a0 \u00a0 \u00a0 request_uri = unquote(environ['REQUEST_URI'])\r\n\u00a0 \u00a0 \u00a0 \u00a0 script_name = unquote(environ.get('SCRIPT_NAME', ''))\r\n\u00a0 \u00a0 \u00a0 \u00a0 offset = request_uri.startswith(script_name) and len(environ['SCRIPT_NAME']) or 0\r\n\u00a0 \u00a0 \u00a0 \u00a0 environ['PATH_INFO'] = request_uri[offset:].split('?', 1)[0]\r\n\u00a0 \u00a0 \u00a0 \u00a0 return self.app(environ, start_response)\r\n\r\n# Set the application\r\napplication = get_wsgi_application()\r\napplication = PassengerPathInfoFix(application)\r\n<\/pre>\n<\/li>\n<li>Use a text editor to create a basic\u00a0<em>index.html<\/em>\u00a0file in the\u00a0<em>~\/myapp\/templates\/static_pages<\/em> directory. The file can be as simple as a text that says\u00a0<strong>Hello world!<\/strong><\/li>\n<li>Next, we&#8217;ll use the <em><strong>migrate<\/strong><\/em> command, which is responsible for applying and unapplying migrations.\n<p>Type the following command:<\/p>\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">python ~\/myapp\/manage.py migrate<\/pre>\n<\/div>\n<p><a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7424\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-783x439.png\" alt=\"\" width=\"643\" height=\"361\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-783x439.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-300x168.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-768x431.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-50x28.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-1536x862.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-60x34.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate-100x56.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-migrate.png 1822w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<li>Next, we&#8217;ll set up the superuser account. This is useful if you need to create an initial superuser account or if you need to generate superuser accounts for your site(s) programmatically.)\n<ul>\n<li>Type the following command:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">python ~\/myapp\/manage.py createsuperuser<\/pre>\n<\/div>\n<\/li>\n<li>At the\u00a0<span class=\"UI\">Username<\/span> prompt, type the administrator username and then press Enter.<\/li>\n<li>Type the administrator&#8217;s e-mail address at the Email address prompt and then press Enter.<\/li>\n<li>At the\u00a0<span class=\"UI\">Password<\/span> prompt, type the administrator password and then press Enter.<a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7425\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-783x162.png\" alt=\"\" width=\"643\" height=\"133\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-783x162.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-300x62.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-768x159.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-50x10.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-1536x317.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-60x12.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser-100x21.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/Python-createsuperuser.png 1782w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Type the following command to collect the static files:\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">python ~\/myapp\/manage.py collectstatic<\/pre>\n<\/div>\n<div class=\"note msg-box\">    \t\t<div class=\"hts-messages hts-messages--info   hts-messages--withicon \"   >\r\n    \t\t\t    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\tIf you are asked if you want to overwrite existing files, type\u00a0<span class=\"user-input\">yes<\/span> and then press Enter.    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7426\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-783x101.png\" alt=\"\" width=\"643\" height=\"83\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-783x101.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-300x39.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-768x99.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-50x6.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-1536x198.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-60x8.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files-100x13.png 100w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/python-collect-static-files.png 1724w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/div>\n<\/li>\n<li>In cPanel, restart the Python application:\n<ul>\n<li>Log in to cPanel.<\/li>\n<li>In the\u00a0<strong>SOFTWARE<\/strong>\u00a0section of the cPanel home screen, click\u00a0<strong>Setup Python App<\/strong>.<\/li>\n<li>Under\u00a0<span class=\"UI\">WEB APPLICATIONS<\/span>, locate the\u00a0<em>myapp<\/em> application and click the\u00a0<strong><em><span class=\"button\">Restart<\/span><\/em><\/strong>\u00a0icon.<br \/>\n<a href=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-7427\" src=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-783x297.png\" alt=\"\" width=\"643\" height=\"244\" srcset=\"https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-783x297.png 783w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-300x114.png 300w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-768x292.png 768w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-50x19.png 50w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-1536x584.png 1536w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-2048x778.png 2048w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-60x23.png 60w, https:\/\/chemicloud.com\/kb\/wp-content\/uploads\/2022\/04\/restart-python-app-100x38.png 100w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Test the Django site:\n<ul>\n<li>Use your browser to <em>http:\/\/www.<span class=\"variable\">example.com<\/span><\/em>, where\u00a0<span class=\"variable\"><em>example.com<\/em><\/span>\u00a0represents your domain name. The\u00a0<em>index.html<\/em>\u00a0file should load.<\/li>\n<li>Use your browser to <em>http:\/\/www.<span class=\"variable\">example.com<\/span>\/admin<\/em>, where\u00a0<span class=\"variable\"><em>example.com<\/em><\/span>\u00a0represents your domain name. You should see the Django administration login page. To log in, use the superuser credentials that you created earlier.<\/li>\n<\/ul>\n<div class=\"tip msg-box\">\n<p>If the website does not appear in your browser, try running the <em>passenger_wsgi.py<\/em>\u00a0file manually. To do this, type the following command:<\/p>\n<div class=\"highlight-wrapper\">\n<pre class=\"command\">python ~\/myapp\/passenger_wsgi.py\r\n<\/pre>\n<\/div>\n<p>There should not be any text output to the console when you run this file. If there are any errors, check the syntax in the configuration files.<\/p>\n<\/div>\n<\/li>\n<\/ol>\n<h4 id=\"More-Information\"><span id=\"more-information\">More Information<\/span><\/h4>\n<p>That&#8217;s it; now you know how to install and set up a Django Application.<\/p>\n<p>Now that you have a Django app up and running, you can start the real work of developing your applications. The following resources can help:<\/p>\n<ul>\n<li>To view the official Django documentation, please visit\u00a0<a href=\"https:\/\/docs.djangoproject.com\/\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/docs.djangoproject.com<\/a>.<\/li>\n<li>For information about Django extensions, please visit\u00a0<a href=\"https:\/\/github.com\/django-extensions\/django-extensions\" rel=\"nofollow noopener\" target=\"_blank\">https:\/\/github.com\/django-extensions\/django-extensions<\/a>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn to quickly install and set up a Django application with the cPanel graphical interface and from the command line. Prerequisites You will need a general knowledge of programming concepts to go through this tutorial, and Python is recommended. You&#8217;ll also require a Python Hosting&#8230;<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"ht-kb-category":[213],"ht-kb-tag":[],"class_list":["post-7406","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-python"],"_links":{"self":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/7406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/comments?post=7406"}],"version-history":[{"count":8,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/7406\/revisions"}],"predecessor-version":[{"id":7428,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb\/7406\/revisions\/7428"}],"wp:attachment":[{"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/media?parent=7406"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=7406"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/chemicloud.com\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=7406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}