Introduction to Django

Introduction to Django

To help you understand the fundamentals of Django and build a strong foundation in Django.

ยท

6 min read

Knowing a programming language will only get you so far ๐Ÿ‘€ . You'll never get things done before the deadline โŒ if you have to build everything yourself. It's a great idea to pick up a framework โœ”๏ธ once you've mastered a programming language ๐Ÿ”ฐ . Django is the most popular Python full-stack framework. Once you've mastered it, creating web applications will be quick and extremely easy! โœจ

In this blog, we will look at some features of Django and demonstrate its ease of use ๐Ÿ‘‘ . If you are excited as I am, let's dive in ๐Ÿค— .
Assumptions for the reader:

  • You have a basic knowledge of Python ๐Ÿ‘๐Ÿป
  • You are excited!๐Ÿ™Œ๐Ÿป

Before we get there, letโ€™s understand a web framework and why we need it. ๐Ÿค”

A web framework is a server-side application framework designed to support the development of dynamic websites ๐Ÿ’ป . Django is one such framework available for Python ๐Ÿ”ฐ . Basically, Django is a code library that makes the life of a web developer much easier ๐Ÿ‘ฉโ€๐Ÿ’ปโ€‹ .

But how? How exactly does a web framework helpโ“
A web framework is a collection of class/APIs with predefined codes that you can use in your program to add a feature to your web application ๐ŸŒ .โ€‹

Web Framework.png

So, we have a web framework with a set of APIs โœ…. We just need to add our snippets of code wherever required โ€” and done! ๐ŸŽ‰ That solves the problem.

So, what is Django?

The Web framework for Perfectionists with Deadlines.

Django Logo.png

๐Ÿ“Œ Simply defined, Django is an open-source Python web framework that allows web and app developers to create and deploy big projects โ€‹โ€‹๐Ÿ‘จโ€๐Ÿ’ป โ€‹rapidly, safely, and in a consistent, "clean" style. ๐Ÿ”— It comes with a set of out-of-the-box tools that support, enrich, and accelerate ๐Ÿ’จ the traditional web development process, allowing you to complete otherwise difficult tasks quickly and to a high standard. โ†—๏ธ

It also makes working with databases a lot easier ๐Ÿ”ฐโ€‹โ€‹โ€‹. You don't need to work directly with a database because Django takes care of creating the database on the go ๐Ÿค๐Ÿป as the user creates models. You can easily swap from one SQL database to the other at the same time.๐Ÿ’ฏ With Django, you can have a fully functional, secure, and admin-editable website in just a few hours. ๐ŸŒŸ

Nevertheless, it's a framework worth having on your portfolio!๐Ÿคฉ

Features of Django

๐Ÿ’ก Some features Django offers us are:

Features of Django.png

Is there anything built with Django that I'm familiar with?๐Ÿค”

You have, without a doubt! ๐Ÿ™Œ๐Ÿป A few of them are listed here:

Django Applications.png

Django MVT Architecture

๐Ÿ“Œ Django follows the MVT Pattern. What is MVT?
The MVT pattern is a type of software design pattern. ๐Ÿ‘‡๐Ÿป It is made up of three major components:

  • ๐Ÿ“ Model - It aids in database management. Your database is defined in the backend โœ”.
  • ๐Ÿ“ View - This executes the business logic and interacts with the model to carry data and render a template โœ”.
  • ๐Ÿ“ Template - It handles the User Interface โœ”.

Django MVT Architecture.png

๐Ÿ’ก So, the process is pretty simple. A user sends the request via the browser โžก๐ŸŒ. Django acts as a controller โœ”, checking the URL for available resources and the associated view is called ๐Ÿ‘๐Ÿป. The model and template interact with the view ๐Ÿค๐Ÿป, which retrieves data from the database via the model โ†ฉ, formats it, and renders with the help of the template as a response. โœ…

Why Djangoโ‰

Advantages of Django.png

  • ๐Ÿ“ ORM - Here, you can define your data models โœ”.
  • ๐Ÿ“ Django comes with a fully-featured and secured authentication system โ€‹๐Ÿ‘จโ€๐Ÿ’ปโ€‹. It handles your user counts, permissions, etc โœ”.
  • ๐Ÿ“ It provides a powerful and production-ready interface to manage content on your site ๐Ÿ“‹. If you want to add a user or create a group โ€‹๐Ÿ“ฑโ€‹, Django has an in-built admin interface created automatically โœ”.
  • ๐Ÿ“ Django offers full support for translating into different languages plus locale scale-specific formatting (e.g., dates, time, time zones) โœ”.

So, where do I begin with?๐Ÿ˜ฏ

No worries at all! ๐Ÿค— AI Probably has got you covered.๐Ÿ™Œ๐Ÿป We are soon launching a FREE 3-hour crash course on โ€œPython with Djangoโ€. ๐Ÿ’ฏ

Python With Django - AI Probably.png

๐Ÿ’ก This course will teach you Django from the ground up ๐Ÿ“ˆ, so you don't need any prior knowledge to get started, just a basic understanding of Python ๐Ÿ”ฐ. We start from the basics โ†—๏ธ and work our way up to understanding the ๐Ÿ“ Django MVT architecture, ๐Ÿ“ setting up SQLite Database , ๐Ÿ“ adding views and templates to our website, ๐Ÿ“ handling requests and responses - step by step ๐Ÿ“‘. This course has it all covered in great detail ๐Ÿ“ and backed up with a complete example course project โ€‹โ€‹๐Ÿ‘จโ€๐Ÿ’ปโ€‹.

Whatโ€™s more? We have gamification-based Learning! โ€‹๐ŸŽฎโ€‹ What does that mean?
๐Ÿ”† That means you learn complex topics through interactive games ๐ŸŽฎ on our website! โœ… With our latest advancement in Gamified Learning methods, you now stand a chance to improve your learning engagement and see your skills grow exponentially! ๐Ÿ“ˆ

Letโ€™s build a project now!

The Django community ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ is a vibrant group of talented programmers โ€‹โ€‹๐Ÿ‘จโ€๐Ÿ’ปโ€‹, and there are numerous tools to help you get started. Also, excellent documentation provided by Django; extremely straightforward and very informative ๐Ÿ“Œ.

๐Ÿ’ก Let us create a small project using Django .

Now, to begin, you'll need Python installed ๐Ÿ”ฐ. Python comes pre-loaded on OS X and Linux-based systems, so if you're using one of those, you're good to go โœ”. If you're using Windows, โ€‹๐Ÿ‘จโ€๐Ÿ’ปโ€‹ you'll need to download and install Python from the Python website .

Now, all we have to do is open up a terminal ๐Ÿ’ป and run

pip install django

to install Django without impacting anything else. The most recent version of Django will be downloaded and installed โœ”. To get started with Django, we'll need to create a project. Navigate to the folder โ†ช (using terminal) where you want to create your project and type

django-admin startproject myproject

๐Ÿ“Œ If you look inside this directory, you'll notice that it has created a myproject folder with the following structure:

myproject/ 
    manage.py 
    myproject/ 
        __init__.py
        settings.py 
        urls.py 
        wsgi.py

โ˜๐Ÿป This is the default project structure for a Django project. Django comes with a built-in server that you may use to test your app โ€‹๐Ÿ’ปโ€‹. It makes it very easy to get your projects up and running ๐ŸŒŸ. Run the server:

python manage.py runserver

๐Ÿš€ Youโ€™ll see the server startup and direct you towards http://127.0.0.1:8000.

Django Deployment.JPG

What does each of these files doโ”

When you run startproject, four files are generated: manage.py, settings.py, urls.py, and wsgi.py.

  1. ๐Ÿ“ The manage.py file replaces the django-admin command we used earlier; it is your main entry point โ†ช into your application and runs any management commands related to our project, such as creating an admin user. It is extremely unlikely that you will need to modify this file ๐Ÿšซ .
  2. ๐Ÿ“ The settings.py file contains all of our project's settings ๐Ÿ“, such as the project's name, the URL it will live on, and so on.
  3. ๐Ÿ“ The urls.py file is the one that contains the routing information for all Django requests; it maps various URLs to their corresponding views ๐ŸŽฏ .
  4. ๐Ÿ“ When you deploy your project to a server, the wsgi.py file is used. It enables a WSGI HTTP server, such as Gunicorn, to mount your application and allows HTTP requests ๐Ÿš€.

I hope you have learned a lot from this article. For learning about a front-end web framework, check out our article on Introduction to React . Watch out for more helpful content and be sure to stay connected on our social media handles!
Happy Learning! ๐ŸŽ‰

ย