{"id":9351,"date":"2021-08-17T13:14:33","date_gmt":"2021-08-17T13:14:33","guid":{"rendered":"https:\/\/linuxways.net\/?p=9351"},"modified":"2021-08-17T13:14:33","modified_gmt":"2021-08-17T13:14:33","slug":"how-to-install-django-on-alma-linux-rocky-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/red-hat\/how-to-install-django-on-alma-linux-rocky-linux\/","title":{"rendered":"How to Install Django on Alma Linux | Rocky Linux"},"content":{"rendered":"<p>Django is a free and open-source, python web development framework that provides a number of tools to enhance software development. Django\u2019s primary goals are simplicity, re-usability, rapid development, and scalability. Instagram, Pinterest, Mozilla, and Knight Foundation are among the well-known websites built with Django.<\/p>\n<p>In this guide, we will install and learn how to use Django in AlmaLinux and Rocky Linux 8.<\/p>\n<h2><strong>Step 1: Install Python and PIP<\/strong><\/h2>\n<p>Since Django is a python based framework, we first need to install Python and PIP on our system. Pip is a command-line utility that is used to install python packages. Run:<\/p>\n<pre><strong>$ sudo dnf install python36 python3-pip<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"188\" class=\"wp-image-9352\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-323.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-323.png 722w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-323-300x78.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/strong><\/p>\n<p>After the installation is complete, confirm the installed python version with the command:<\/p>\n<pre><strong>$ python3 -V<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"423\" height=\"59\" class=\"wp-image-9353\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-324.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-324.png 423w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-324-300x42.png 300w\" sizes=\"auto, (max-width: 423px) 100vw, 423px\" \/><\/p>\n<p>Also, check the pip version with the command:<\/p>\n<pre><strong>$ pip3 -V<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"59\" class=\"wp-image-9354\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-325.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-325.png 666w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-325-300x27.png 300w\" sizes=\"auto, (max-width: 666px) 100vw, 666px\" \/><\/strong><\/p>\n<h2><strong>Step 2: Install Django on Rocky Linux 8 | AlmaLinux 8 via PIP3<\/strong><\/h2>\n<p>Next, let\u2019s install Django using the pip package manager. To achieve this, execute:<\/p>\n<pre><strong>$ sudo pip3 install Django<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"787\" height=\"380\" class=\"wp-image-9355\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-326.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-326.png 787w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-326-300x145.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-326-768x371.png 768w\" sizes=\"auto, (max-width: 787px) 100vw, 787px\" \/><\/strong><\/p>\n<p>After Django is successfully installed, check the version installed with the command:<\/p>\n<pre><strong>$ django-admin --version<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"59\" class=\"wp-image-9356\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-327.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-327.png 546w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-327-300x32.png 300w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><\/strong><\/p>\n<p>The Django version at the time of installation is 3.2.6<\/p>\n<h2><strong>Step 3: Create a Django Sample Project<\/strong><\/h2>\n<p>After you have successfully installed Django on Rocky Linux 8 | AlmaLinux 8, we are now ready to build our first project.<\/p>\n<p>First, let&#8217;s create a new directory for our project.<\/p>\n<pre><strong>$ sudo mkdir \u2013p \/home\/project\/django<\/strong><\/pre>\n<p>Next, go into the directory and start a new project using use Django-admin command followed by startproject and the name of your application which is \u201cproject1\u201d in this case.<\/p>\n<pre><strong>$ django-admin startproject project1<\/strong><\/pre>\n<p>After this, navigate to the newly created app \u201cproject1\u201d:<\/p>\n<pre><strong>$ cd project1<\/strong><\/pre>\n<p>Inside our project directory there exists a <strong>manage.py <\/strong> Python file. We need to migrate the pending changes as shown below.<\/p>\n<pre><strong>$ sudo python3 manage.py migrate<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"714\" height=\"418\" class=\"wp-image-9357\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-328.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-328.png 714w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-328-300x176.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/p>\n<p>All migrations have been successfully applied.<\/p>\n<h2><strong>Step 4: Create a Django superuser account <\/strong><\/h2>\n<p>You now need to create a superuser account in order to access the \u2018admin\u2019 panel. Run the command:<\/p>\n<pre><strong>$ sudo python3 manage.py createsuperuser<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"677\" height=\"115\" class=\"wp-image-9358\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-329.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-329.png 677w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-329-300x51.png 300w\" sizes=\"auto, (max-width: 677px) 100vw, 677px\" \/><\/strong><\/p>\n<p>You will need to provide a username, email address, and password for the superuser.<\/p>\n<h2><strong>Step 5: Configure Firewall Rules for Django<\/strong><\/h2>\n<p>Django listens on port 8000 by default. We, therefore, need to allow port 8000 through the firewall as shown below:<\/p>\n<pre><strong>$ sudo firewall-cmd --add-port=8000\/tcp --zone=public --permanent <\/strong><\/pre>\n<pre><strong>$ sudo firewall-cmd --permanent --add-port=80\/tcp <\/strong><\/pre>\n<pre><strong>$ sudo firewall-cmd --reload<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"115\" class=\"wp-image-9359\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-330.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-330.png 767w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-330-300x45.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/strong><\/p>\n<p>The commands will output success.<\/p>\n<p>To verify that the port is allowed through the firewall, run:<\/p>\n<pre><strong>$ sudo firewall-cmd --list-ports <\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"70\" class=\"wp-image-9360\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-331.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-331.png 618w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-331-300x34.png 300w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/strong><\/p>\n<p>From the output, port 8000 is listed.<\/p>\n<p>Next, we need to modify the <strong>settings.py<\/strong> file inside our project folder to allow django to be accessed by external users. We can either specify a server\u2019s IP address or assign the [\u2018*\u2019] in the allowed_hosts field. When using [\u2018*&#8217;], the application can be accessed from any network.<\/p>\n<p>Open the settings.py file with an editor and add [\u2018*&#8217;] in the ALLOWED_HOSTS field.<\/p>\n<pre><strong>$ sudo nano project1\/settings.py<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"389\" class=\"wp-image-9361\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-332.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-332.png 781w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-332-300x149.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-332-768x383.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/strong><\/p>\n<p>Once done, save the changes and exit.<\/p>\n<h2><strong>Step 6: Start the Django Application<\/strong><\/h2>\n<p>We are now ready to launch the Django application after successfully completing all of the above configurations. To start the app, use the commands shown below.<\/p>\n<pre><strong>$ sudo python3 manage.py runserver 0.0.0.0:8000<\/strong><\/pre>\n<p>Next, we can access the Web Interface using the URL <a href=\"http:\/\/server-ip:8000\">http:\/\/server-IP:8000<\/a>. You will see the webpage below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1197\" height=\"675\" class=\"wp-image-9362\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-333.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-333.png 1197w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-333-300x169.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-333-1024x577.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-333-768x433.png 768w\" sizes=\"auto, (max-width: 1197px) 100vw, 1197px\" \/><\/p>\n<p>To access the admin dashboard, add <strong>\/admin<\/strong> to the end of the URL.<\/p>\n<pre><strong>$ <\/strong><a href=\"http:\/\/server-ip:8000\/admin\"><strong>http:\/\/server-IP:8000\/admin<\/strong><\/a><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1187\" height=\"710\" class=\"wp-image-9363\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334.png 1187w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334-1024x613.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/08\/word-image-334-501x300.png 501w\" sizes=\"auto, (max-width: 1187px) 100vw, 1187px\" \/><\/p>\n<p>Provide the credentials you used when creating the superuser account and press the \u2018Login\u2019 button to log in.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>You are now ready to start creating Django projects on your Rocky Linux \/ AlmaLinux system.<\/p>","protected":false},"excerpt":{"rendered":"<p>Django is a free and open-source, python web development framework that provides a number of tools to enhance software development. Django\u2019s primary goals are simplicity, re-usability, rapid development,&hellip;<\/p>","protected":false},"author":1,"featured_media":9438,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[165],"tags":[444,369],"class_list":["post-9351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-red-hat","tag-almalinux","tag-django"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9351","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=9351"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9351\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/9438"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=9351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=9351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=9351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}