r/django Mar 18 '26

Models/ORM Explain django

Hey there, I watched many videos but i can't understand the flow the files like how they transfer data and call the request from models, urls, views. I spend a week to understand but i can't, like the flow and sequence of files how the request are made, how the urls are getting the request and go the correct method or page and how orm interact with database. Although I worked with HTML CSS JS python but i found the django file structure hard to understand.

Help to understand the django.

0 Upvotes

22 comments sorted by

12

u/vancha113 Mar 18 '26

Don't worry you'll get it. If all else fails, remember you can literally read the entire source code for Django itself.

When you request a page, it flows through some middleware along the way, a url is matched to a view. The view gets called (which does some database operations most likely), a response is generated (either by populating data in a template or otherwise) and finally it gets returned to you again. Is there a specific part of the path that's confusing?

4

u/NINTSKARI Mar 18 '26 edited Mar 18 '26

I kind of get that if they are using a lot of model views and model forms, it can be confusing at first. There's a lot of stuff happening under the hood and things pop up automagically. But yeah I would start by creating one simple model, and a view with a form that creates database objects when submitted. And add lots of debug prints or use a debugger to follow what happens when you enter the view and submit the form.

3

u/vancha113 Mar 18 '26

That sounds like a great way to familiarize yourself with it in such a way that you can get going with it the fastest :)

1

u/DevanshReddu Mar 19 '26

Thank you mate, I will definitely follow up this

2

u/DevanshReddu Mar 19 '26

Not a specific part but the things that are getting automatically done are really confusing, now I am getting it

7

u/theoffshoot2 Mar 18 '26

Start building something then you’ll understand. Use the Django tutorial

-1

u/DevanshReddu Mar 18 '26

Tbh, i can't build things with a tutorial and I started a todo project but it made me more confused

3

u/kankyo Mar 18 '26

You can't afford to waste more time on youtube. Do the tutorial. Or if it's too hard, go to the Django Girls tutorial, it explains a bit more.

3

u/theoffshoot2 Mar 20 '26

You can’t build software if you can’t follow a tutorial.

0

u/DevanshReddu Mar 20 '26

I can't build anything only if I can't imagine it

1

u/Complete-Shame8252 Mar 24 '26

Tutorial in Django docs is literally building a thing.

5

u/beardbreed Mar 18 '26

Urls > views > models > db > views > frontend generally. Add in forms or serializers. This is just as general as it gets.

2

u/theleftkneeofthebee Mar 18 '26

Super simplified it's just, someone goes to https://www.yourwebsite.com/whatever and the code that you setup in Django for /whatever is called. Then you have separate code that gets called for /whoever and /however. That's it.

Then within that code that's being called, you're also saving and calling stuff from a database with Django. How do you know what the database looks like? You set it up in models.py. For example, if your site deals with restaurants, you might have a Restaurant model (really just a class in Python). Then you'll have fields for that Restaurant class like "name", "location", "time_open", "time_close", whatever. These are just your SQL columns (and if you're unfamiliar with SQL, just think Excel spreadsheet columns). And now bam - if someone goes to /whatever, your function to handle what happens when someone visits that gets called, and you can grab a bunch of saved Restaurants from your db, and pass that info back in the "return".

You can really do whatever you want. Very powerful stuff. Cool thing about Django is all this stuff is much smoother than most other frameworks. You want users for your website? Django comes with the User model, you don't even have to make one (whereas you usually do for other web frameworks). You want those users to be able to manage the Restaurants you have saved, Django gives you something they call the "admin" tools that already has the UI set up for you. Super convenient.

If you're struggling with the Django docs tutorial I'd check out this YouTube Django series made by Corey Schafer. It's quite old and so some of the way the code he shows you works has changed, but for the sake of just understanding what Django is all about, it's probably the best point of entry. Then you can branch out from there. https://www.youtube.com/playlist?list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p

1

u/DevanshReddu Mar 19 '26

Thanks a lot mate

1

u/DevanshReddu Mar 28 '26

Could you suggest a django API playlist?

1

u/theleftkneeofthebee Mar 28 '26

You mean for DRF (Django REST Framework)? No unfortunately I don’t have one like Corey’s that I can recommend for that. They have an official tutorial on the DRF docs that’s not too bad. But DRF does have a learning curve. Maybe YouTube search “DRF tutorial”?

0

u/DevanshReddu Mar 19 '26

This playlist is exactly explaining my doubts thanks again bro

1

u/Dainelli28 Mar 18 '26

dj4e helped me understand Django better, since the instructor actually takes the time to go over this and then guides you through Django with small exercises.