Samuel Tucker

Samuel Tucker

1558859343

How To Install the Django Web Framework on Ubuntu 18.04

In this guide, you will get Django up and running on an Ubuntu 18.04 server. After installation, you will start a new project to use as the basis for your site.

Introduction

Django is a full-featured Python web framework for developing dynamic websites and applications. Using Django, you can quickly create Python web applications and rely on the framework to do a good deal of the heavy lifting.

Different Methods

There are different ways to install Django, depending upon your needs and how you want to configure your development environment. These have different advantages and one method may lend itself better to your specific situation than others.

Some of the different methods include:

  • Global install from packages: The official Ubuntu repositories contain Django packages that can be installed with the conventional apt package manager. This is simple, but not as flexible as some other methods. Also, the version contained in the repositories may lag behind the official versions available from the project.
  • Install with **pip** in a virtual environment: You can create a self-contained environment for your projects using tools like venv and virtualenv. A virtual environment allows you to install Django in a project directory without affecting the larger system, along with other per-project customizations and packages. This is typically the most practical and recommended approach to working with Django.
  • Development version install with **git**: If you wish to install the latest development version instead of the stable release, you can acquire the code from the Git repo. This is necessary to get the latest features/fixes and can be done within your virtual environment. Development versions do not have the same stability guarantees as more stable versions, however.

Prerequisites

Before you begin, you should have a non-root user with sudo privileges available on your Ubuntu 18.04 server.

Global Install from Packages

If you wish to install Django using the Ubuntu repositories, the process is very straightforward.

First, update your local package index with apt:

sudo apt update

Next, check which version of Python you have installed. 18.04 ships with Python 3.6 by default, which you can verify by typing:

python3 -V

You should see output like this:

Output
Python 3.6.5 

Next, install Django:

sudo apt install python3-django

You can test that the installation was successful by typing:

django-admin --version
Output
1.11.11 

This means that the software was successfully installed. You may also notice that the Django version is not the latest stable version.

Install with pip in a Virtual Environment

The most flexible way to install Django on your system is within a virtual environment. We will show you how to install Django in a virtual environment that we will create with the venv module, part of the standard Python 3 library. This tool allows you to create virtual Python environments and install Python packages without affecting the rest of the system. You can therefore select Python packages on a per-project basis, regardless of conflicts with other projects’ requirements.

Let’s begin by refreshing the local package index:

sudo apt update

Check the version of Python you have installed:

python3 -V
Output
Python 3.6.5 

Next, let’s install pip from the Ubuntu repositories:

sudo apt install python3-pip

Once pip is installed, you can use it to install the venv package:

sudo apt install python3-venv

Now, whenever you start a new project, you can create a virtual environment for it. Start by creating and moving into a new project directory:

mkdir ~/newproject
cd ~/newproject

Next, create a virtual environment within the project directory using the python command that’s compatible with your version of Python. We will call our virtual environment my_env, but you should name it something descriptive:

python3.6 -m venv my_env

This will install standalone versions of Python and pip into an isolated directory structure within your project directory. A directory will be created with the name you select, which will hold the file hierarchy where your packages will be installed.

To install packages into the isolated environment, you must activate it by typing:

source my_env/bin/activate

Your prompt should change to reflect that you are now in your virtual environment. It will look something like (my_env)username@hostname:~/newproject$.

In your new environment, you can use pip to install Django. Regardless of your Python version, pip should just be called pip when you are in your virtual environment. Also note that you do not need to use sudo since you are installing locally:

pip install django

You can verify the installation by typing:

django-admin --version
Output
2.1 

Note that your version may differ from the version shown here.

To leave your virtual environment, you need to issue the deactivate command from anywhere on the system:

deactivate

Your prompt should revert to the conventional display. When you wish to work on your project again, re-activate your virtual environment by moving back into your project directory and activating:

cd ~/newproject
source my_env/bin/activate

Development Version Install with Git

If you need a development version of Django, you can download and install Django from its Git repository. Let’s do this from within a virtual environment.

First, let’s update the local package index:

sudo apt update

Check the version of Python you have installed:

python3 -V
Output
Python 3.6.5 

Next, install pip from the official repositories:

sudo apt install python3-pip

Install the venv package to create your virtual environment:

sudo apt install python3-venv

The next step is cloning the Django repository. Between releases, this repository will have more up-to-date features and bug fixes at the possible expense of stability. You can clone the repository to a directory called ~/django-dev within your home directory by typing:

git clone git://github.com/django/django ~/django-dev

Change to this directory:

cd ~/django-dev

Create a virtual environment using the python command that’s compatible with your installed version of Python:

python3.6 -m venv my_env

Activate it:

source my_env/bin/activate

Next, you can install the repository using pip. The -e option will install in “editable” mode, which is necessary when installing from version control:

pip install -e ~/django-dev

You can verify that the installation was successful by typing:

django-admin --version
Output
2.2.dev20180802155335 

Again, the version you see displayed may not match what is shown here.

You now have the latest version of Django in your virtual environment.

Creating a Sample Project

With Django installed, you can begin building your project. We will go over how to create a project and test it on your development server using a virtual environment.

First, create a directory for your project and change into it:

mkdir ~/django-test
cd ~/django-test

Next, create your virtual environment:

python3.6 -m venv my_env

Activate the environment:

source my_env/bin/activate

Install Django:

pip install django

To build your project, you can use django-admin with the startproject command. We will call our project djangoproject, but you can replace this with a different name. startproject will create a directory within your current working directory that includes:

  • A management script, manage.py, which you can use to administer various Django-specific tasks.
  • A directory (with the same name as the project) that includes the actual project code.

To avoid having too many nested directories, however, let’s tell Django to place the management script and inner directory in the current directory (notice the ending dot):

django-admin startproject djangoproject .

To migrate the database (this example uses SQLite by default), let’s use the migrate command with manage.py. Migrations apply any changes you’ve made to your Django models to your database schema.

To migrate the database, type:

python manage.py migrate

You will see output like the following:

Output
Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying admin.0003_logentry_add_action_flag_choices... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying sessions.0001_initial... OK 

Finally, let’s create an administrative user so that you can use the Djano admin interface. Let’s do this with the createsuperuser command:

python manage.py createsuperuser

You will be prompted for a username, an email address, and a password for your user.

Modifying ALLOWED_HOSTS in the Django Settings

To successfully test your application, you will need to modify one of the directives in the Django settings.

Open the settings file by typing:

nano ~/django-test/djangoproject/settings.py

Inside, locate the ALLOWED_HOSTS directive. This defines a whitelist of addresses or domain names that may be used to connect to the Django instance. An incoming request with a Host header that is not in this list will raise an exception. Django requires that you set this to prevent a certain class of security vulnerability.

In the square brackets, list the IP addresses or domain names that are associated with your Django server. Each item should be listed in quotations, with separate entries separated by a comma. If you want requests for an entire domain and any subdomains, prepend a period to the beginning of the entry:

~/django-test/djangoproject/settings.py

. . . ALLOWED_HOSTS = ['your_server_ip_or_domain', 'your_second_ip_or_domain', . . .] 

When you are finished, save the file and exit your editor.

Testing the Development Server

Once you have a user, you can start up the Django development server to see what a fresh Django project looks like. You should only use this for development purposes. When you are ready to deploy, be sure to follow Django’s guidelines on deployment carefully.

Before you try the development server, make sure you open the appropriate port in your firewall. If you followed the initial server setup guide and are using UFW, you can open port 8000 by typing:

sudo ufw allow 8000

Start the development server:

python manage.py runserver your_server_ip:8000

Visit your server’s IP address followed by :8000 in your web browser:

http://your_server_ip:8000 

You should see something that looks like this:

To access the admin interface, add /admin/ to the end of your URL:

http://your_server_ip:8000/admin/ 

This will take you to a log in screen:

How To Install the Django Web Framework on Ubuntu 18.04

If you enter the admin username and password that you just created, you will have access to the main admin section of the site:

How To Install the Django Web Framework on Ubuntu 18.04

When you are finished looking through the default site, you can stop the development server by typing CTRL-C in your terminal.

The Django project you’ve created provides the structural basis for designing a more complete site. Check out the Django documentation for more information about how to build your applications and customize your site.

Conclusion

You should now have Django installed on your Ubuntu 18.04 server, providing the main tools you need to create powerful web applications. You should also know how to start a new project and launch the developer server. Leveraging a complete web framework like Django can help make development faster, allowing you to concentrate only on the unique aspects of your applications.

#python #django #ubuntu

What is GEEK

Buddha Community

How To Install the Django Web Framework on Ubuntu 18.04
Chet  Lubowitz

Chet Lubowitz

1595429220

How to Install Microsoft Teams on Ubuntu 20.04

Microsoft Teams is a communication platform used for Chat, Calling, Meetings, and Collaboration. Generally, it is used by companies and individuals working on projects. However, Microsoft Teams is available for macOS, Windows, and Linux operating systems available now.

In this tutorial, we will show you how to install Microsoft Teams on Ubuntu 20.04 machine. By default, Microsoft Teams package is not available in the Ubuntu default repository. However we will show you 2 methods to install Teams by downloading the Debian package from their official website, or by adding the Microsoft repository.

Install Microsoft Teams on Ubuntu 20.04

1./ Install Microsoft Teams using Debian installer file

01- First, navigate to teams app downloads page and grab the Debian binary installer. You can simply obtain the URL and pull the binary using wget;

$ VERSION=1.3.00.5153
$ wget https://packages.microsoft.com/repos/ms-teams/pool/main/t/teams/teams_${VERSION}_amd64.deb

#linux #ubuntu #install microsoft teams on ubuntu #install teams ubuntu #microsoft teams #teams #teams download ubuntu #teams install ubuntu #ubuntu install microsoft teams #uninstall teams ubuntu

Servo Node

Servo Node

1626801695

Install VirtualBox in Ubuntu 21.04/20.04/18.04 › Servo Node

VirtualBox is a widely known and open-source tool offered by Oracle. It’s a cross platform virtualization application that can be installed on any system that allows users to run a number of guest operating systems on single machine over a virtual system.

Means, with the usage of VirtualBox on your system, you can easily install many operating systems and can run them simultaneously which can be helpful to develop, demonstrate, deploy and test applications on a single machine.

How to install VirtualBox On Ubuntu 18.04, 20.04 and 21.04?

Since the virtualization system offered by Oracle is available for cross platforms, even Ubuntu users can install the app and take its benefits. In order to install VirtualBox in Ubuntu variants, there’s a number of approaches that can be helpful.

Installing using default repository

sudo apt install virtualbox

Install using official DEB package

Visit the Virtualbox download page and download DEB package in your machine, and run the following command to install the package using ATP command.

sudo apt install ./virtualbox-6.1_6.1.22-144080_Ubuntu_bionic_amd64.deb

for more approaches and information, Read Here

#install virtual box on ubuntu #install virtual box on ubuntu 18.04 #install virtual box on ubuntu 20.04 #install virtual box on ubuntu21.04

Chet  Lubowitz

Chet Lubowitz

1595515560

How to Install TeamViewer on Ubuntu 20.04

TeamViewer is a cross-platform, proprietary application that allows a user to remotely connect to a workstation, transfer files, and have online meetings. In this tutorial, we will walk you through how to install TeamViewer on Ubuntu 20.04 Desktop through the command line.

Prerequisites

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.

Installing TeamViewer on Ubuntu

01- To install TeamViewer, first, download the TeamViewer .deb package. So, open the Terminal and run the following wget command.

$ wget https://download.teamviewer.com/download/linux/teamviewer_amd64.deb

02- Once you have downloaded the TeamViewer‘s Debian package, execute the following command to install Teamviewer:

$ sudo apt install ./teamviewer_amd64.deb

The system will prompt you with a [Y/n] option. Type ‘Y‘ and hit the enter key in order for to continue the installation.

03- Once the installation is done, you can launch TeamViewer either by typing the command teamviewer in your terminal or by clicking on the TeamViewer icon (Activities -> TeamViewer).

04- A pop-up License Agreement will be displayed. To proceed, click on the Accept License Agreement button.

#linux #ubuntu #install teamviewer #install teamviewer ubuntu #teamviewer #teamviewer ubuntu #teamviewer ubuntu install #ubuntu install teamviewer

Arvel  Parker

Arvel Parker

1592209410

How to Install PgAdmin 4 on Ubuntu 20.04

pgAdmin is the leading graphical Open Source management, development and administration tool for PostgreSQL. pgAdmin4 is a rewrite of the popular pgAdmin3 management tool for the PostgreSQL database.

In this tutorial, we are going to show you how to install pgAdmin4 in Server Mode as a web application using apache2 and Wsgi module on Ubuntu 20.04 LTS.

#databases #linux #ubuntu #install pgadmin4 #install pgadmin4 ubuntu #install pgadmin4 ubuntu 20 #pgadmin4 #ubuntu pgadmin4 #ubuntu pgadmin4 install

Brain  Crist

Brain Crist

1595372400

How to Install Android Studio on Ubuntu 20.04

1./ Install Android Studio Using APT

Method 1./ Install Android Studio Using APT

1- We need to add official repository to the sources list. Therefore, type the below command to add the Android Studio repository:

$ sudo add-apt-repository ppa:maarten-fonville/android-studio

02- Now let’s install Android studio and all the software dependencies as below.

$ sudo apt update
$ sudo apt install android-studio

Method 2./ Install Android Studio Using snap

We can install using the snap tool. So, use the below command to install Android Studio:

$ sudo snap install android-studio --classic

2./ Starting Android Studio

01- You can start Android Studio either by typing the command android-studio in your terminal or by clicking on the Android Studio icon (Activities -> Android Studio).

How to Install Android Studio on Ubuntu 20.04

02- When you start Android Studio for the first time, a window like the following will appear asking you to import Android Studio settings from a previous installation. However, if you have a previous installation of Android Studio, simply browse to the configuration folder. If not, go with the default option which is Do not import settings.

How to Install Android Studio on Ubuntu 20.04

03- Click on the Next button, and you will be presented with a window to choose your type of setup you want for Android Studio. So, let’s choose Standard which will install the most common settings and options as below.

How to Install Android Studio on Ubuntu 20.04

04- Click Next and you’ll be taken to the following window to choose your UI theme:

How to Install Android Studio on Ubuntu 20.04

05- You’ll be taken to a window to verify your chosen settings. Simply click on Next. Finally, wait for the Wizard to download and install the required dependencies before you can start your first Android project

How to Install Android Studio on Ubuntu 20.04

#linux #ubuntu #install android studio #install android studio ubuntu #install sdk ubuntu #sdk #sdk install android studio #ubuntu install android studio