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:
Django installation using pip
Setting up your first Django project
Creating first Django app
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
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!
Subscribe by Email
Follow Updates Articles from This Blog via Email
1 Comments
A great effort to explain every details to django project setup. Very much helpful for a beginner to enrich basic of django.
Reply Delete