Takeaways from this article:
- Setting up python in Ubuntu system.
- Creating a virtual environment in python.
- Creating a sample application with Django Framework.
1. Setting up python in Ubuntu system.
1.1 Check if python exists in your system.
python3 --version
If Python is not installed, continue to the next step, else skip to point 2.
1.2 Update and refresh repository list.
sudo apt update
1.3 Install supporting softwares.
sudo apt install software-properties-common
1.4 Install python 3.8
sudo apt install python3.8
1.5 Check installed python version
python3 --version
2. Creating virtual environment in python.
2.1 Install python-pip
sudo apt install -y python3-pip
2.2 Install python virtual-environment
sudo apt install -y python3-venv
2.3 Create virtual-environment
python3 -m venv <virtual_enviornment_name>
2.4 Activate virtual-environment
source <virtual_enviornment_name>/bin/activate
Your command prompt will now be prefixed with the name of your environment:
(virtual_enviornment_name) raghu:~/Projects
2.5 Test your virtual-environment
python3
This will open a python shell for you.
Congratulations your virtual environment has been created, let's create our first Django app.
3. Creating a sample application with Django Framework.
3.1 Check if Django exists.
django-admin --version
If Django is not installed, continue to the next step, else skip to step 3.3.
3.2 Install Django
sudo apt install python3-django
3.3 Setting up Django and starting your server.
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/
You can open the same URL in the browser to see your project
4. Conclusion
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.
Top comments (2)
Great Stuff! Quite easy to follow.
Thanks!!