Getting Started with Django

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 pyth…


This content originally appeared on DEV Community and was authored by Raghu Kapur

Takeaways from this article:

  1. Setting up python in Ubuntu system.
  2. Creating a virtual environment in python.
  3. 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
Alt Text

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.


This content originally appeared on DEV Community and was authored by Raghu Kapur


Print Share Comment Cite Upload Translate Updates
APA

Raghu Kapur | Sciencx (2021-06-26T13:28:07+00:00) Getting Started with Django. Retrieved from https://www.scien.cx/2021/06/26/getting-started-with-django/

MLA
" » Getting Started with Django." Raghu Kapur | Sciencx - Saturday June 26, 2021, https://www.scien.cx/2021/06/26/getting-started-with-django/
HARVARD
Raghu Kapur | Sciencx Saturday June 26, 2021 » Getting Started with Django., viewed ,<https://www.scien.cx/2021/06/26/getting-started-with-django/>
VANCOUVER
Raghu Kapur | Sciencx - » Getting Started with Django. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/26/getting-started-with-django/
CHICAGO
" » Getting Started with Django." Raghu Kapur | Sciencx - Accessed . https://www.scien.cx/2021/06/26/getting-started-with-django/
IEEE
" » Getting Started with Django." Raghu Kapur | Sciencx [Online]. Available: https://www.scien.cx/2021/06/26/getting-started-with-django/. [Accessed: ]
rf:citation
» Getting Started with Django | Raghu Kapur | Sciencx | https://www.scien.cx/2021/06/26/getting-started-with-django/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.