18
Getting Started with Django
- Setting up python in Ubuntu system.
- Creating a virtual environment in python.
- Creating a sample application with Django Framework.
python3 --version
If Python is not installed, continue to the next step, else skip to point 2.
sudo apt update
sudo apt install software-properties-common
sudo apt install python3.8
python3 --version
sudo apt install -y python3-pip
sudo apt install -y python3-venv
python3 -m venv <virtual_enviornment_name>
source <virtual_enviornment_name>/bin/activate
Your command prompt will now be prefixed with the name of your environment:
(virtual_enviornment_name) raghu:~/Projects
python3
This will open a python shell for you.
Congratulations your virtual environment has been created, let's create our first Django app.
django-admin --version
If Django is not installed, continue to the next step, else skip to step 3.3.
sudo apt install python3-django
django-admin startproject <project_name>
This command would have created a folder with your project name. Navigate to the folder using the "cd" command.
Inside the folder you will see the file "manage.py", a key file in Django projects.
Run the following command to migrate the database(Django uses SQLite by default) and sync your changes.
python3 manage.py migrate
This will create some migrations and extra files, which we will discuss in the upcoming blogs.
For now you can start your webserver using the following command:
python3 manage.py runserver
In the terminal you will see the development server starting at http://127.0.0.1:8000/
In this blog we learned about how to setup a Django Application.
In the upcoming blogs we will learn to create a fully functional application.
18