{"id":1235,"date":"2019-02-27T12:54:04","date_gmt":"2019-02-27T07:24:04","guid":{"rendered":"http:\/\/blog.openwebsolutions.in\/?p=1235"},"modified":"2019-02-27T15:01:58","modified_gmt":"2019-02-27T09:31:58","slug":"learn-install-django-set-up-project-ubuntu","status":"publish","type":"post","link":"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/","title":{"rendered":"Learn to Install Django and Set Up project on Ubuntu"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Django is a free and open-source web framework which is written in Python.<\/span><span style=\"font-weight: 400\"> Django can be installed on a server in many ways, mainly there are three different ways to install Django<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Django installation with pip.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Install Django with virtualenv.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><span style=\"font-weight: 400\">Install Django from it&#8217;s github repository.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">After installing Django, I will show you the first steps to start a new project with the Django web framework.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s start the installation process<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-weight: 400\">Step 1 \u2014 Install Python and pip<\/span><\/h2>\n<p><span style=\"font-weight: 400\">first, we need to update the local APT repository to install Python<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">$ sudo apt-get update &amp;&amp; sudo apt-get -y upgrade<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">After this we can install Python 3 by using the following command:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">$ sudo apt-get install python3<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">After installing Python, we need pip in order to install packages from PyPi, Python\u2019s package repository.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">$ <\/span><span style=\"font-weight: 400\">sudo apt-get install -y python3-pip<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-weight: 400\">Step 2 \u2014 Install virtualenv<\/span><\/h2>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-install-python-3-and-set-up-a-programming-environment-on-an-ubuntu-16-04-server#step-2-%E2%80%94-setting-up-a-virtual-environment\"><span style=\"font-weight: 400\">virtual environment<\/span><\/a><span style=\"font-weight: 400\">(virtualenv) is where user can install software and Python packages, this will isolate the installed software and packages from your machine\u2019s global environment. It will prevent conflicting packages or software from interacting with each other.<\/span><\/p>\n<p><span style=\"font-weight: 400\">For installing virtualenv, we will use the pip3 command<\/span><\/p>\n<p><span style=\"font-weight: 400\">$ <\/span><span style=\"font-weight: 400\">pip3 install virtualenv<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">After the execution of this command, virtualenv is successfully installed in your computer<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-weight: 400\">Step 3 \u2014 Install Django<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Option 1: Install Django Globally with pip<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">As we have already installed pip.<\/span><span style=\"font-weight: 400\"> Now we can use the pip command to install python packages. now install Django on our server using the following pip command:<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">$ <\/span><i><span style=\"font-weight: 400\">pip install django==1.10<\/span><\/i><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">We set django==1.10 to get a specific version. If you want some other version, just change the number<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Option 2: <\/span><span style=\"font-weight: 400\">Install Django with virtualenv<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Virtualenv is already installed Now we can use the virtualenv command to create a new environment with python3 as default python version. Now create a new environment &#8220;myenv&#8221; with python3 as the python version and pip3 for the Django installation.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><i><span style=\"font-weight: 400\">virtualenv &#8211;python=python3 <\/span><\/i><span style=\"font-weight: 400\">myenv<\/span><\/p>\n<p><span style=\"font-weight: 400\">myenv is the name of the environment. The command will create a new directory called myenv which contains the directories bin, include and lib. The virtualenv has been created, now let&#8217;s log into the new environment with the command below:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">source <\/span><\/i><span style=\"font-weight: 400\">myenv<\/span><i><span style=\"font-weight: 400\">\/bin\/activate<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Or you can run the following command<\/span><\/p>\n<p><span style=\"font-weight: 400\">myenv<\/span><i><span style=\"font-weight: 400\">\/bin\/activate<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Next, install Django in the newly created virtual environment<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><i><span style=\"font-weight: 400\">pip install django==1.10<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Option 3: <\/span><span style=\"font-weight: 400\">Install Django from it&#8217;s github repository.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>If you want the latest version of Django, then you can install directly from the source.<\/p>\n<p><span style=\"font-weight: 400\">Now I will show you how to install Django manually from the Django Git repository. First Install git using the following command below:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">apt-get install git -y<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Next, create virtual environment for python and activate it:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">virtualenv &#8211;python=python3 django-git<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">source django-git\/bin\/activate<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Then clone the Django git repository with the command below:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">cd django-git<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">git clone git:\/\/github.com\/django\/django django-dev<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Install django with this pip command:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">pip install -e django-dev\/<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">-e = \u00a0Install a package in editable mode or a local package. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Step 4 \u2014 Creating a Django Test Project<\/span><\/p>\n<p><span style=\"font-weight: 400\">In this step, we will install Django inside a virtual environment and then start our first project with Django.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Install virtualenv on the server and create a new environment named &#8216;newdjango&#8217; :<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">pip install virtualenv<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">virtualenv &#8211;python=python3 <\/span><\/i><span style=\"font-weight: 400\">newdjango<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now go to the &#8216;newdjango&#8217; directory and activate the virtual environment, then install Django with the pip command:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">cd <\/span><\/i><span style=\"font-weight: 400\">newdjango<\/span><i><span style=\"font-weight: 400\">\/<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">source bin\/activate<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">pip install django==1.10<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Next, create a new project called &#8216;myblog&#8217; with the django-admin command:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">django-admin startproject myblog<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Go to the &#8216;myblog&#8217; directory and run the &#8216;manage.py&#8217; file :<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">cd myblog\/<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">python manage.py runserver<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">The runserver option will create an HTTP connection with python on localhost IP and port 8000.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now check from your browser: localhost:8000<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400\">Next, we will configure the Django admin. A database for a superuser will automatically generated by Django. Before we create the superuser, run the following command :<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">python manage.py migrate<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">migrate: make adds the models (adding fields, deleting etc.) into the database scheme, the default database is sqlite3.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now create the admin\/superuser:<\/span><\/p>\n<p><i><span style=\"font-weight: 400\">python manage.py createsuperuser<\/span><\/i><\/p>\n<p>&nbsp;<\/p>\n<p><i><span style=\"font-weight: 400\">Username (leave blank to use &#8216;root&#8217;): admin<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">Email address: admin@mydjango.com<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">Password:<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">Password (again):<\/span><\/i><\/p>\n<p><i><span style=\"font-weight: 400\">Superuser created successfully.<\/span><\/i><\/p>\n<p><span style=\"font-weight: 400\">Now the Django superuser has been added, now you can execute the runserver command, then go to the browser and visit the django admin page<\/span><\/p>\n<p><span style=\"font-weight: 400\">Visit Django admin page: 192.168.1.9:8000\/admin\/. This will show the login admin login page, now log in with username <\/span><b>admin<\/b><span style=\"font-weight: 400\"> and your password, you will see the admin page.<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, now Django has been successfully installed inside a virtual environment and we&#8217;ve created a sample Django project named &#8216;newdjango&#8217;.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Django is a free and open-source web framework which is written in Python. Django can be installed on a server in many ways, mainly there are three different ways to install Django &nbsp; Django installation with pip. Install Django with virtualenv. Install Django from it&#8217;s github repository. &nbsp; After installing Django, I will show you [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":1246,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[96,21,5],"tags":[97,34],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v14.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn to Install Django and Set Up project on Ubuntu<\/title>\n<meta name=\"robots\" content=\"index, follow\" \/>\n<meta name=\"googlebot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta name=\"bingbot\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn to Install Django and Set Up project on Ubuntu\" \/>\n<meta property=\"og:description\" content=\"Django is a free and open-source web framework which is written in Python. Django can be installed on a server in many ways, mainly there are three different ways to install Django &nbsp; Django installation with pip. Install Django with virtualenv. Install Django from it&#8217;s github repository. &nbsp; After installing Django, I will show you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Openweb Solutions Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-27T07:24:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-27T09:31:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/186096_6b71_14.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n<meta name=\"twitter:card\" content=\"summary\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/\",\"name\":\"Openweb Solutions Blog\",\"description\":\"Transforming ideas into reality\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/openwebsolutions.in\/blog\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/#primaryimage\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/wp-content\/uploads\/2019\/02\/186096_6b71_14.jpg\",\"width\":750,\"height\":422},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/#webpage\",\"url\":\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/\",\"name\":\"Learn to Install Django and Set Up project on Ubuntu\",\"isPartOf\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/#primaryimage\"},\"datePublished\":\"2019-02-27T07:24:04+00:00\",\"dateModified\":\"2019-02-27T09:31:58+00:00\",\"author\":{\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/399d10640115db2d90b44eb60be86bbf\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/openwebsolutions.in\/blog\/learn-install-django-set-up-project-ubuntu\/\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#\/schema\/person\/399d10640115db2d90b44eb60be86bbf\",\"name\":\"Suman Saha\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/openwebsolutions.in\/blog\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/05a5f8f27a59bb3550048704dcc6b041?s=96&r=g\",\"caption\":\"Suman Saha\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1235"}],"collection":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=1235"}],"version-history":[{"count":4,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1235\/revisions"}],"predecessor-version":[{"id":1250,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/posts\/1235\/revisions\/1250"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media\/1246"}],"wp:attachment":[{"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=1235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=1235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/openwebsolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=1235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}