Getting Started with Django: A Step-by-Step Guide
Mr #1738
Posted on October 18, 2024
Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development,In this guide I will help on how to setup Django from scratch.
1 Setting up a django project
first check if python is installed on your computer running
python3 --version
on your terminal,if not installed follow the above link to install python on your computer.https://www.python.org/
Create a directory where you will store your work for easy efficiency ,on your terminal run
mkidr Learning-django
then
cd Learning-django
to change into your working directory.
Setting up a Virtual Environment
t's a good practice to create a virtual environment for each Django project to keep dependencies up and running the python code consistently.
# Create a virtual environment
python -m venv env
# Activate the virtual environment
# For Windows:
env\Scripts\activate
# For macOS/Linux:
source env/bin/activate
Once activated, your terminal prompt should reflect the virtual environment above.
Installing Django
Now that your virtual enviroment is set up install as below.
django py running
pip install django
verify the installation with
django-admin --version
step2 creating new djangoproject
with Django installed, you create a new Django project by running
django-admin startproject mysite
cd mysite
This will create the following structure
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
manage.py:
A command-line utility that lets you interact with this Django project in various ways.mysite/:
A directory that is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. mysite.urls).mysite/__init__.py:
An empty file that tells Python that this directory should be considered a Python package.mysite/settings.py:
Settings/configuration for this Django project. Django settings will tell you all about how settings work.mysite/urls.py:
URL declarations for routing requests.mysite/asgi.py:
An entry-point for ASGI-compatible web servers to serve your project. See How to deploy with ASGI for more details.mysite/wsgi.py:
An entry-point for WSGI-compatible web servers to serve your project.
step3 Running the development server
To see if everything is set up correctly, run the development server :
python3 manage.py runserver
Visit http://127.0.0.1:8000/ in your browser, and you should see the Django welcome page.
Django comes with a default SQLite database with well be using for this article.
db.sqlite3 manage.py mysite
Posted on October 18, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.