How to install Django on ubuntu

Опубликовано: 17 Декабрь 2022
на канале: Quickloss3
452
18

First, let’s update the local package index:
sudo apt update && apt upgrade -y

Check the version of Python you have installed:
python3 -V

install pip and venv:
sudo apt install python3-pip python3-venv -y

cloning the Django repository:
git clone https://github.com/django/dja ~/django-dev

Change to this directory:
cd ~/django-dev

Create a virtual environment:
python3 -m venv vr_env

Activate it:
source vr_env/bin/activate

install the repository:
pip install -e ~/django-dev

verify that the installation:
django-admin --version


Creating a Sample Project


create a directory for your project and change into it:
mkdir ~/django-test
cd ~/django-test

create your virtual environment:
python3 -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, type:
python manage.py migrate

create an administrative user:
python manage.py createsuperuser


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

~/django-test/djangoproject/settings.py
ALLOWED_HOSTS = ['your_server_ip_or_domain', 'your_second_ip_or_domain', . . .]

save and exit.

Testing the Development Server
sudo ufw allow 8000

Start the development server:
python manage.py runserver your_server_ip:8000

Visit:

http://your_server_ip:8000

http://your_server_ip:8000/admin/


Смотрите видео How to install Django on ubuntu онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Quickloss3 17 Декабрь 2022, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 452 раз и оно понравилось 18 людям.