Django tutorials – how the django project works

django tutorials www.devpyjp.com

Hello, my dear Django learners..! we know that python Django is a web framework, it will help developers to develop web applications ridiculously fast and secure way. In this Django tutorials, we are going to see how the Django project works effectively.

Django works based on MVT architecture, not MVC. The main difference between MVC and MVT occurs at the controller part. In Django, views works also as controllers. let ‘s understand it step by step.

Overview of the Django project

when we create a new django project , defaultly we will get some files in our django project folder. If you don’t know how to create django project chek our django tutorials how to create django project

when you successfully created a django project then you will get a folder structure like below. 

Django project structure

here, “devpyjp” is a python Django project folder and under that, we have __init__.py, asgi.py, settings.py,urls.py, and wsgi.py files. out of that folder, we have SQLite database file and manage.py file.

let me explain the important files in the Django project folder.

manage.py:

It is used to execute the whole Django project when giving the below command.

 python manage.py runserver

It will manage all admin commands like creating users and database migrations, we will see in the next tutorials.

settings.py

It will manage all our apps and other third-party apps. here we need to configure our templates, static files, and media files. there a lot of things you need to do here based on your project idea.

urls.py

This file helps us to configure our app and project URLs.Django allows us to create our own and clean SEO friendly URLs. we will see in our later Django tutorials.

If you want to know the four pillars of python you need to create a Django app. let’s create your Django app.

Create a Django app

To create a Django app in the Django project we need to execute the below command. here blog is an app name .you can give your own Django app.

 python manage.py startapp blog

Now look at your project structure, you get another folder inside the Django project folder named blog in my case.

we don’t bother about all the files created by Django, but we need to know the most important four files in every Django project. These four files are pillars of the Django project.

4 pillars of the Django project

There are four important files in every python Django project. they are

  • models.py
  • views.py
  • urls.py
  • and templates. # I know its a folder, not existed here.

models.py

This is the file where we can write our all database logics. It will create tables in our database for our Django project. we need to keep on eye on this file because storage is important for every project.

Note: we don’t need to create a separate database for our project. Django framework creates for us.

views.py

views have a key role in every Django project. It is the file where we write our logics which are required and requested by the user.

views send the data to templates from models. views worked as an intermediate between templates and models.

urls.py

we can create app-level URLs for every Django app exclusively and later we need to configure our app URLs to Django project URLs.

Templates

It consists of HTML files for both project and apps or only for a project that is totally up to you. templates help the user to interact with our Django project and send the output or results to the user.

let me give a clear picture to you, then you definitely understood how the Django project works.

so when actually,

  • we sent a request to the Django project or Django website, you definitely hit a URL through templates. that URL check the views.
  • views sent a request to models and get the data requested by the user and sent through URLs to templates.
  • Now finally the user gets the ret the results through templates.

If you are happy with our Django tutorials then please appreciate us through comment and subscribe to our newsletter. we created Django tutorials for beginners like you, check that here.

If you subscribe to our newsletter, you will get a FREE Django tutorial pdf. so subscribe to us now. Thank you.

Don't miss out!
Subscribe To Newsletter

Receive top Machine learning & Python news, lesson ideas, project tips, FREE Ebooks and more!

Invalid email address
Thanks for subscribing!

Leave a Reply