{"id":6669,"date":"2018-12-28T22:28:42","date_gmt":"2018-12-28T22:28:42","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=6669"},"modified":"2018-12-28T23:13:20","modified_gmt":"2018-12-28T23:13:20","slug":"how-to-install-django-web-framework-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/28\/how-to-install-django-web-framework-on-ubuntu-18-04\/","title":{"rendered":"How to install Django Web Framework on Ubuntu 18.04"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linux4one.com\/wp-content\/uploads\/2018\/12\/How-to-install-Django-on-Ubuntu-18.04.jpg\" alt=\"How to install Django on Ubuntu 18.04\" width=\"750\" height=\"350\" \/>How to install Django on Ubuntu 18.04<\/p>\n<h2>Install Django on Ubuntu 18.04<\/h2>\n<p><a href=\"https:\/\/www.djangoproject.com\">Django<\/a> is the most popular web framework which is designed to develop fully featured Python Web Applications. By using Django you can build secure, scalable and maintainable dynamic web applications. In this tutorial, you are going to install Django on Ubuntu 18.04 using Python Virtual Environment. The best thing to use Python Virtual Environment is you can create multiple Django Environments on a single computer without affecting other Django projects. It also will become easier to install a specific module for each project.<\/p>\n<h3>Prerequisites<\/h3>\n<p>Before you start to install Django on Ubuntu 18.04. You must have the non-root user account on your system with sudo privileges.<\/p>\n<p>Install tree command to use it in further tutorial for better understanding.<\/p>\n<p>sudo apt install tree<\/p>\n<h3>Confirm Python Installation and Install venv<\/h3>\n<p>Python 3.6 is by default installed on Ubuntu 18.04. Confirm the Python installation and check the Python version by typing following command.<\/p>\n<p>python3 -V<\/p>\n<p>Output should be as give below. Note version number may vary.<\/p>\n<p>Output:<br \/>\nPython 3.6.7<\/p>\n<p>By using venv module we can create virtual environments in Python 3.6. To get venv module we need to install python3-venv package to do so enter following command.<\/p>\n<p>sudo apt install python3-venv<\/p>\n<p>Now we can create Virtual Environment for Django Applications.<\/p>\n<h3>Create Virtual Environment<\/h3>\n<p>Create a new directory for your Django application and go inside the directory.<\/p>\n<p>mkdir new_django_app &amp;&amp; cd new_django_app<\/p>\n<p>Now create virtual Environment by running following command. It will create directory named venv which includes supporting files, Standard python library, Python binaries, Pip package manager.<\/p>\n<p>python3 -m venv venv<\/p>\n<p>To start using the virtual environment we need to activate it. To activate the virtual environment run following command.<\/p>\n<p>source venv\/bin\/activate<\/p>\n<p>Now your path will change and it will show the name of your virtual environment (venv)<\/p>\n<h3>Install Django<\/h3>\n<p>Now install Django by using Pip (Python Package Manager).<\/p>\n<p>pip install Django<\/p>\n<p>Confirm the installation and Check the version typing following command.<\/p>\n<p>python -m django &#8211;version<\/p>\n<p>The output should be as given below. NOTE: you can get slightly different output.<\/p>\n<p>Output:<br \/>\n2.1.4<\/p>\n<h3>Creating Django Project<\/h3>\n<p>Create a Django project by using django-admin utility named newdjangoapp. Enter following command to create new Django project.<\/p>\n<p>django-admin startproject newdjangoapp<\/p>\n<p>Now newdjangoapp directory will be created. Check the directory structure by using the following command. This directory has manage.py file used to manage the project and other Django specific files about database configuration settings, routes, and settings<\/p>\n<p>tree newdjangoapp\/<\/p>\n<p>Output should be<\/p>\n<p>newdjangoapp\/<br \/>\n|&#8211; manage.py<br \/>\n`&#8211; mydjangoapp<br \/>\n|&#8211; __init__.py<br \/>\n|&#8211; settings.py<br \/>\n|&#8211; urls.py<br \/>\n`&#8211; wsgi.py<\/p>\n<p>Now go inside newdjangoapp directory.<\/p>\n<p>cd newdjangoapp<\/p>\n<p>Now we need to migrate the database.<\/p>\n<p>python manage.py migrate<\/p>\n<p>Output should be:<\/p>\n<p>Operations to perform:<br \/>\nApply all migrations: admin, auth, contenttypes, sessions<br \/>\nRunning migrations:<br \/>\nApplying contenttypes.0001_initial&#8230; OK<br \/>\nApplying auth.0001_initial&#8230; OK<br \/>\nApplying admin.0001_initial&#8230; OK<br \/>\nApplying admin.0002_logentry_remove_auto_add&#8230; OK<br \/>\nApplying admin.0003_logentry_add_action_flag_choices&#8230; OK<br \/>\nApplying contenttypes.0002_remove_content_type_name&#8230; OK<br \/>\nApplying auth.0002_alter_permission_name_max_length&#8230; OK<br \/>\nApplying auth.0003_alter_user_email_max_length&#8230; OK<br \/>\nApplying auth.0004_alter_user_username_opts&#8230; OK<br \/>\nApplying auth.0005_alter_user_last_login_null&#8230; OK<br \/>\nApplying auth.0006_require_contenttypes_0002&#8230; OK<br \/>\nApplying auth.0007_alter_validators_add_error_messages&#8230; OK<br \/>\nApplying auth.0008_alter_user_username_max_length&#8230; OK<br \/>\nApplying auth.0009_alter_user_last_name_max_length&#8230; OK<br \/>\nApplying sessions.0001_initial&#8230; OK<\/p>\n<p>Create administrative user running following command.<\/p>\n<p>python manage.py createsuperuser<\/p>\n<p><u> NOTE: Above command can prompt you for Username, Password and Email Address for your user.<\/u><\/p>\n<h3>Testing the development server<\/h3>\n<p>Run development server using following command.<\/p>\n<p>python manage.py runserver<\/p>\n<p>The output should be:<\/p>\n<p>Performing system checks&#8230;<\/p>\n<p>System check identified no issues (0 silenced).<br \/>\nDecember 27, 2018 &#8211; 18:26:02<br \/>\nDjango version 2.1.4, using settings &#8216;mydjangoapp.settings&#8217;<br \/>\nStarting development server at http:\/\/127.0.0.1:8000\/<br \/>\nQuit the server with CONTROL-C.<\/p>\n<p><u>NOTE: If you are using the virtual machine then you need to add your server IP address inside settings.py file.<\/u><\/p>\n<p>Go to http:\/\/127.0.0.1:8000\/ in your browser you will get following page.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/image\/gif;base64,R0lGODdhAQABAPAAAP\/wAAACwAAAAAAQABAEACAkQBADs=\" alt=\"django home page\" width=\"1031\" height=\"688\" \/>django home page<\/p>\n<p>You can go to admin page by visiting http:\/\/127.0.0.1:8000\/admin\/ page.<\/p>\n<p>Enter username and password we have created recently after successful authentication you will be redirected to the administrative page.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/image\/gif;base64,R0lGODdhAQABAPAAAP\/wAAACwAAAAAAQABAEACAkQBADs=\" alt=\"django admin login page\" width=\"1191\" height=\"691\" \/>django admin login page<\/p>\n<p>Stop the development server pressing Ctrl+C in terminal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/lxer.com\/image\/gif;base64,R0lGODdhAQABAPAAAP\/wAAACwAAAAAAQABAEACAkQBADs=\" alt=\"Django home for admin\" width=\"1334\" height=\"484\" \/>Django home for admin<\/p>\n<h3>Deactivate The Virtual Environment<\/h3>\n<p>To deactivate virtual environment after work run following command.<\/p>\n<p>deactivate<\/p>\n<h3>Conclusion<\/h3>\n<p>You have successfully learned how to install Django Web Framework on Ubuntu 18.04. If you have any queries please don\u2019t forget to comment below.<\/p>\n<p><u> NOTE: You can create multiple development environments repeating above steps.<\/u><\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=264326\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to install Django on Ubuntu 18.04 Install Django on Ubuntu 18.04 Django is the most popular web framework which is designed to develop fully featured Python Web Applications. By using Django you can build secure, scalable and maintainable dynamic web applications. In this tutorial, you are going to install Django on Ubuntu 18.04 using &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/28\/how-to-install-django-web-framework-on-ubuntu-18-04\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to install Django Web Framework on Ubuntu 18.04&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6669","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=6669"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6669\/revisions"}],"predecessor-version":[{"id":6863,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6669\/revisions\/6863"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=6669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=6669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=6669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}