Friday, October 8, 2021

thumbnail

Your First Django Project Setup : A Complete Guide to Django Installation



Your First Django Project Setup : 

A Complete Guide to Django Installation


As you are reading this content, I think you already know what Django is. Django is a backend framework written in python programming language. Basically Django is a python library which has to be installed. The only requirement is that python has to be installed previously and it has to be added to the path. 


Steps:

  1. Django installation using pip

  2. Setting up your first Django project

  3. Creating first Django app

  4. Running the project



Step 1: Django installation


For installing Django simply go to your command prompt and write


pip install django





It will take sometime. The latest version of Django will be installed with this command. For installing a specific version of Django you have to write the command


pip install django==version_number


To check the installation in command prompt write


pip list


It will show all the packages installed with their respective versions.



Step 2: Setting up your first Django project


In Django at first a project is created then inside the projects apps are created. A project may contain one app or more apps based on the functionality. For example for user registration One app, for CRUD operations another app. It is done to make the structure simple. For making the project, open command prompt in the folder where you want to keep your project and write


django-admin startproject projectName


With this a folder will be created as ‘projectName’ inside which there will be a folder named ‘projectName’ and a ‘manage.py’ file.


File structure after creating the first project:


|--projectName

|--projectName

|--__pycache__

|--__init__.py

|--asgi.py

|--settings.py

|--urls.py

|--wsgi.py

|--manage.py

Step 3:Creating first django app


Your project may contain a number of apps. To create an app, change the directory to the ‘projectName’ (Here I have shown the project as ‘projectName’). For that in the command prompt write


cd projectName


Now you are inside the project directory where the manage.py file is located. Now write the command


python manage.py startapp myApp


Here myApp is the name of your app. With this command a folder named ‘myApp’ will be created. This is your first app. With this the file structure will look like this:

|--projectName

|--projectName

|--__pycache__

|--__init__.py

|--asgi.py

|--settings.py

|--urls.py

|--wsgi.py

|--myApp

|--migrations

|--__init__.py

|--admin.py

|--apps.py

|--models.py

|--tests.py

|--views.py

|--db.sqlite3

|--manage.py



Step 4: Running the project

To check whether your installation procedure was correct and it is working go to the cmd again without changing the directory and write


python manage.py runserver


If the installation process is alright the command prompt will be something like this



Now go to your browser and type the url 'http://127.0.0.1:8000/' which is the address of your local server running on port 8000. The server is running and in the browser the interface will come like this:




Which means your Django installation is successful. Now we are good to go for next tasks. 


There can be error in the installation process. Fill free to write those in the comment section.

Thank you!





Tags :

Subscribe by Email

Follow Updates Articles from This Blog via Email

1 Comments

avatar

A great effort to explain every details to django project setup. Very much helpful for a beginner to enrich basic of django.

Reply Delete