Transcript: What is Django?
Hello, welcome to a new episode of Django Chat.
Today we're going to talk about what is Django.
I'm Will Vincent and joined by Carlton Gibson.
Hello.
And this is an episode that's we've wanted to do for a long time because we both work with Django professionally, but also in a teaching capacity where we're dealing with people who are new to programming or new to web development or just new to Django, there's a lot of different ways to explain what Django actually is.
So we're gonna dive into that today.
So Carlton, when someone asks you, what is Django, what do you say?
Right, good question.
Right.
So Django is well, the web framework, right?
So what's a web framework?
What's a web request?
What's the web?
The web is your browser is talking to, you type in a URL, it sends off a request to a server, that server compiles a response in the form of an HTML page and sends it back to you.
That's the fundamental task.
There are various bits of that which are the same every single time.
And so you don't want to you don't want to build those from scratch every single time.
So a web framework is a tool which gives you the basic building blocks enabling you to build your web application that serves those responses.
So there's a view layer, there's a template layer, there's an ORM.
These are bits of the Django, of Django that you wouldn't you don't want to create from scratch.
Um that's because it's super yeah, because it's well, I was gonna say boring.
It's not boring, but it's the same.
Every site has you know 90% of the functionality is the same.
It needs to talk to a database, it needs to handle requests, you know, so load this page.
And because it's so much of it is the same, it makes sense that web frameworks uh emerge.
Um basically there's one or two big ones for every programming language.
So Ruby has Ruby on Rails, JavaScript has Express, PHP has Laravel, um, Python has Flask and Django.
And I guess within that there is different philosophies of how you build a web framework.
But yeah, it's a I I mean I usually describe it as it's a set of tools to make it faster so you can focus on what's different about a website, not what's the same.
Yeah, perfect.
They I mean, you know, the tagline is the web framework for perfectionists with the deadline.
So the idea is you want to do it right, but you've got to do it quickly.
Right.
Yeah.
And yeah, and I think that the challenge of this question is, you know, I always ask someone, you know, where are you at?
Like what level are you at?
So if I explain to my mom what a web framework is, my mom is not technical.
Um, I just say, yeah, it's a tool that makes it easier to build websites.
And that's kind of as much as she wants to know, right?
And then if it's somebody learning programming, it's like, well, you know, let's talk about what a website is, which as you said, you know, you need to learn about HTTP, where you do requests and response.
So you load a page each time.
Um, and you can kind of break down the functionality and and you want, you know, there's a lot of things you can get wrong, there's a lot of security things.
And so it makes sense to have a community of millions of people over, you know, in Django's case, what is it, uh 14 years, you know, something like that.
Yeah.
To um, you know, it's not the kind of work you want to do in your own.
And and I always think of it as nobody cares what web framework you use.
No, I mean engineers.
They do care if your site's insecure, or they do care if it's slow, or they do care if it's you know, don't normally.
Exactly.
So it's purely um, you know, sort of a a tool for us developers, but a tool that's awesome and um important.
And you'd be, you know, as a learning exercise, it it would be interesting to build your own web framework, but you would quickly, I think, appreciate why.
Um it's sort of crazy that anyone starts one.
It is these days, like kind of in the early 2000s, everybody wrote their own web framework.
They you know they picked up Pearl, they wrote their web framework in Perl, they picked up PHP, they wrote their own web, and then you had all these homebrew web frameworks around.
And they all had problems.
And you know uh the community ones arose from that kind of Armageddon of homebrew frameworks.
Right.
Well, it's a little bit like the curse of the engineer where you, you know, I love the example of I'm gonna oh I should blog.
Okay.
Let me write a blog, sit down, stare at the blank page.
Uh, you know, you know, I should write, I should use a static site generator.
You know, let me go check out Jekyll or um Gatsby and then look at it and go, uh, you know, it's not quite what I want.
I'm just gonna build my own.
But you know, it's sort of like you're not an engineer unless you've gone ahead and build your own.
And then, you know, weeks later you still haven't written that blog post, and you're like, uh, this is kind of actually harder than I thought.
Maybe I'll just use you know,
but it's it's in a way it's easier to write a static site generator than it is to read the docs of a static giant site generator and work out how it works.
Yes, true.
Um, right.
So so what is all right, so Django, Django is a web framework, it's a set of tools to automate uh which you use to build a website.
There are a lot of, you know, I always say, you know, again, as I mentioned, I start with, so there's programming languages, that's the base layer.
It's a couple popular ones, Python, Ruby, JavaScript, PHP would be the big ones.
And then within that, there's one or two web frameworks.
So you sort of have to go up the ladder in terms of choosing your tools.
Um, you know, I think a big within the web frameworks, there's sort of if if you can make a distinction, there's micro uh frameworks like um Flask, where you have lots of, you know, it's like a manual car.
Um, or you have ones like Django, which are full-bodied, batteries included, it's more like an automatic.
So you do you lose a little bit of control?
Yes, but you don't, you know, it's that's not even it's more, you know, David Hennemier Hansen of Ruby and Rails described it as the difference between a bag of Legos you dump on the floor, that's a microframework, and a truck that just works.
You know, so um we'll do we'll probably do a separate episode on that.
But what you know, there's choices one has to make.
And as the, you know, working with a web framework, that web frameworks architects made choices around um, you know, how much control to give you, but also how much, you know, rope for you to hang yourself with.
Yeah, and I think the the bigger example here is in the JavaScript community, in the Node.js community, where they use these really small micro components and then they have to bolt them together.
And there's an art in knowing which the packages are and how which one relies on which and which works well together and which are maintained, and putting together your package, which then, yeah, you've got maximum control, but there's quite a lot of work in that.
And with the back Django and Rails in particular, they go for the batteries-included approach, so they provide you every not everything you need, but the the all the main components all in one.
You install Django, you know that most of what you need is there, and then you might reach out to the third-party packages in the community for those few bits that aren't.
Right.
Whereas with um a microframework from the beginning, you're gonna have to install half dozen, dozen third-party packages just for you know a basic blog site.
Yeah.
Um you know, because it's just not included.
So different philosophies.
Yeah, there's nothing wrong with that depending on your application, but you know,
I mean, we're clearly biased, but many people are biased, as we are.
And I mean, it really depends on what you need, it depends on the context.
You know, my personal experience, you know, I've used all of these frameworks over the years, and my personal experience is that I'm much more um productive with Django simply because it's all there and I don't have to go search.
This time sent looking for other packages, it's not time well spent.
I can be running my application.
And for me, I can get right down to the view layer and and I know it well.
So there aren't it's it's not like I have more freedom with a micro framework.
Um Right.
You can you can dive, you can change things in Django if you want to, but you don't have to.
Yeah, exactly.
And so for me, I'm much more efficient doing it that way.
You know, Flask might be a little bit more lightweight or whatever, but I have to go and look to the docs and try and remember what the interface is.
Whereas with Django, I know that, I recognize it.
And so it's much quicker for me to produce something in Django than it is in another framework.
Yeah, and there's um we'll link in the notes.
There's a fantastic um PyCon talk from 2017 by Jacob Kaplan Moss called Let's Build a Web Framework, where he goes through basically the ingredients and the choices that you have to make um in a web framework.
And you know, if he were Yeah, so that's three hours long, but worth looking at if you really want to think about these things.
Um and it helps, you know, it helps your appreciation, helps you understand the choices Django makes, because not every choice is perfect, but most of them are good, and the ones that aren't perfect um can be worked on.
So yeah, so let's let's move on.
So why yeah, I think we've covered the next thing you know is why would you recommend Django to someone?
I mean, usually the argument someone says, I want to build a website.
And usually I I try to ask, well, you know, what exactly do you want?
Um if you're you know, Django is a good choice for many people because it's built with Python, which if you're learning programming these days, Python and JavaScript are the two most popular languages.
Um Python probably more in the academic context.
If you have a CS degree, more and more of that education is in Python.
Yeah, and in the business context as well.
Yes.
The whole data science and data analysis and um Jupyter Notebooks.
And I know that you can use JavaScript in Jupyter Notebooks, but it's Python-based, and and the whole Pandas project and the all of that.
Python is um very practical in the real world.
Right.
Yeah, I mean it's and it's
and then Django is probably the go-to web framework in that environment.
I know there's Flask as well, but for people in the real economy, to reach for Django is a much more sensible choice, I think, than to reach for Flask because they they don't exactly as we were just talking about, they don't know the ins and outs of the might of the Flask um ecosystem.
I and I think you know when you start out, the hello World with Flask is simpler than Django.
So I think it's sometimes I see people think that Flask is better for beginners, but often I would argue that you know once you do anything more than Hello World, Django has got your back.
And most of the people I see using Flask are quite advanced developers with very specific use cases, especially around microservices.
So in some ways I think you know Flask is a sort of either end of the spectrum and Django is more in the middle.
And again, you know, you should learn both, but um Django is a great choice, someone who wants to learn web development.
But part of part of the challenge, um, and I've I talked to a lot of people about this, is just the first time you learn web development, there's so much to learn.
And Django and Rails sort of um have a degree of magic in that they solve things for you, and so you sort of back your way into learning how this all works.
But I, you know, I personally think that's the way to do it.
There's no sense in reading a thousand-page manual before you start a website, like build something and then iterate on it, and when you want to customize it, that's a good chance to learn more about you know what is the view layer, how do templates really work, you know, routing.
Um, I personally I I like the ability to just get something done and then backfill rather than have to spend huge amounts of time up front.
Um Yeah, I mean I think people aren't um most learners aren't in a position where they want to learn everything from the first principles and then build up.
They want to get something functional up and running and play with it and then tweak it and learn.
So you couldn't the the great thing with like the Django tutorials or whatever is you can you can get a blog site up and running, which you've built, and it's a functioning blog site, and it's great, and you've got forms and it you can edit and you can you know users can filter by tags and all these great stuff.
And you you haven't really understood all of it, but you've got this this functional thing that works and it's yours and you built it, and then you can grow it and play with it and learn more.
Yeah, yeah.
So in the same way that yeah, Python is uh, you know, a good beginner language choice, but also used at the highest levels, um, Django as well kind of can span uh span that spectrum for you.
Um so what else should we say?
I mean, there's so much, you know, that we have an entire podcast on Django, so there's so many areas we could dive into about you know what Django does, databases, views, URLs, templates.
Um I mean, I guess another, you know, in terms of you know, what is Django, why is Django special, um, you know, it was built from the beginning with this um, you know, for perfectionists on a deadline, this idea of you should be able to work quickly on things, um, you know, and part of that is some of the maybe extra features that not every web framework has is so the admin is one.
So this is right, the admin.
So it was built for a newspaper um company, right?
And they had two or three publications, and they had the development team who were building the the web, the online publications, but they had the content authors who needed to be able to come in and write newspaper articles and enter them into the database.
And so the Django admin was born in this environment, and what that gives you is an instant admin interface on top of so you define some models, which are part the ORM, which we haven't really talked about, but on top of that, the admin just then creates this whole interface which enables you to edit, add, you know, that's got permissions involved with it.
It's it's super, and to get that out of the box for essentially zero effort is one of Django's key features, I think.
It's one of the things that historically has been a drawing point.
It's quite special.
And I think um, you know, at all levels to have a graphical interface way to um interact with the guts is um is very powerful.
You so you can also go into the Django shell, so that's like a command line view, um, which some people prefer.
But you know, even for me, I mean sometimes it's nice to just see my stuff instead of having to live in the command line.
And certainly for beginners, um, you know, when I teach Total Beginners, I don't drop into the Django shell at all.
You know, there is this admin there.
So once you set up your basic things, you can go in and you know add blog posts, you can add comments, you know, you can add users, you can do this in a very visual way that I think is you know great for teaching.
Yeah, and as well, like it doesn't matter how advanced you are, it's almost I can't think of a single case where it wouldn't be worth just doing the four lines of code to create the admin for your model.
Yeah, yeah.
You always want some sort of admin view.
I mean, um, and then especially, yeah, as you said, with the permissions built in, I mean, more and more everyone in a company, even non-technical people, um, need a way to look at the, you know, the business people, marketing sales to look at the data.
And um there's lots of, you know, Django comes with that out of the box, um, which is a super strong feature.
Um, you know, another, you know, I'd say what's the top list of things that makes Django special, you know, forms.
So forms, search bar, entering user input.
Um that's the core of almost every website.
Um, Django really handles that in an elegant way, I would say, um, in terms of you can get up and running quickly, but you also can customize it.
And all the security stuff or the security stuff is very well handled.
Well, like the
important strengths of doing validation and you know the the the thing.
Yeah, there's so many ways you can make a mistake, especially when you're learning, but even as a pro, there's just so many, yeah, so many things that Django uh, you know, and we should mention them among your other projects.
You are now in uh maintain Django Crispy Forms, which is an add-on to
Yeah, so that's that that's good.
Like, I don't know, you might want to have um say you've got a a model field which isn't part of the form.
It enables you to create a nice um form layout, which so you've got like the the form fields that you want editable and then a few model fields and then some more form fields.
It's it's kind of cool for um defining model fields and or or form layouts, um, which are a non-standard.
It makes that into a nice programmatic interface.
So it's it's a good package.
Yeah, and that's and that's um you know, I guess the next point that's an example of a third-party package, which there are many with Django.
So, you know, so Django sort of gives you a lot, batteries included, but then there is a very robust ecosystem of these third-party packages where you can, you know, enhance or customize a built-in feature, or you can have additional functionality that um isn't in Django itself because it's um you know it doesn't need to be, or it, you know, there's a lot to maintain with Django as is, but there's there's you know, there's um so there's a Django packages website um we'll link to that.
Yeah, and we should do a show on our favorite packages, I think.
Yeah, yeah.
They say like third-party packages are Django's secret source, and they for almost anything you can think of, there's there's a third-party package out that implements it, and either it's it's well maintained and and feature complete, in which case just use it, or it's at least a prototype that you can copy and base your own code off, depending on you know the state of completeness of a third-party package.
But yeah, it's it it the richness of Django's ecosystem, especially after all this time, is something irreplaceable, I think.
Yeah, and that's something that I think with experience, you you know, um Django's not a shiny new toy anymore, but it's still being actively worked on and improved.
And that's really uh valuable when you're actually uh have some experience and get burned by um you know, early stage frameworks change a lot.
Yeah.
And you have to ask yourself, are you do you want to have a you know a website or or build a company or and you know have some stability there, or do you want to just play around?
And so, you know, um I I've been burned.
I think a lot of people over the course of their career have been burned by frameworks, new frameworks that change a lot because they have to, but you know, Django is very mature and yet under active development.
Yeah, and it's so good in that respect, in that you can be on the latest version quite easily without any problems because it is stable, it is secure, it is um mature.
And that means that you don't have to w worry that the the new version has broken your entire site and that you're gonna have to restructure everything and then you're gonna end up on an unsupported version.
You know, that we're on version two point, well, nearly to 2.2, we're gonna be on version three this year.
That those big numbers they mean something.
It's not 0 point something something, right?
Right, and yeah, and I mean that's something that um you know, like all good advice, if you haven't experienced this yet, this probably isn't clicking for you, but if you have, it really does.
So trust us, it's a positive to have a mature framework.
Um I think it makes it that's what it is.
Yeah, I think it makes it really exciting.
It it it it means that you can be right on the edge, you can get all the new features, all the bug fixes without having to worry about your site falling over because something changed that you were relying on.
Right.
And again, you know, this is another trap for engineers is how much do you want to work on um the plumbing versus the special sauce?
Um, you know, it's good to do both.
And certainly there are things about the plumbing that are really interesting and challenging.
But you know, for most people, I think you you want to focus on something that differentiates it in some way.
Um, and so using a tool like Django, which can be customized, which can be improved, is the way to spend your time rather than, you know, if you want to write a web framework from scratch, go for it.
But don't kid yourself you can start a company and build a web framework from scratch.
Yeah, yeah, yeah.
That's not gonna work.
You've got to be somewhat conservative in your technology choices.
Like if you're always on the the latest database, always on the latest web framework, always at late on the latest front end framework, you're never gonna get anything built.
Right, right.
But yeah, you know, you need to stay current.
And we have a we'll do a separate episode on Django versions and talk about how you know the Django roadmap for for changes, but um, it is advancing and also well thought out.
So you know if you're on if you're using Django you can stay up to date.
What else?
Testing.
So this is one looking at you JavaScript that um Django has its own tests and also takes advantage of Python's built-in tests and tests are um fantastic to use in Django.
And this is another one where with experience you go how can I not have something with robust testing and yet um not every web framework does.
Well there's two parts to it.
One is the is the way is the web framework itself well tested and Django is.
And this the other is does it provide tools that enable you to write tests for your own code easily and Django does.
So there's those two aspects of it both are important.
Yeah and there's you know you know sort of I guess the the last big thing I would say is um when Django is called a user model so every web framework is going to have some way for users to sign up to log in and there are different choices a framework can make around that um you know Django gives you built-in options but it's also very customizable.
And I think you know that's a good choice that it makes but that's sort of the last major component of any web framework is you need to have some sort of user registration.
And you know there's things like social authentication, two-factor um we can do a whole episode on that but Django gives you something to get up and running and then there are third party packages and built-in ways that you can kind of make your choice because there isn't one user authentication technique that works for everyone at this point.
No like what do you want?
Do you want to be people to be able to create user accounts or give them user accounts and then you want um them to be able to log in and then them to be able to create blog posts of their own or articles of their own or whatever your content is and have that subject their user and then you want to restrict access just to their ones not to everybody's and Django gives you the basic building blocks for all of that and then yeah there's if you want Facebook login there's third party apps for that and if you want two factor authors third party for that you know the this is
where the the ecosystem is great.
There's the foundation and then the surrounding things which add on all the the the extras would it would be impossible it would make you know to include every single thing in the core is just make it a maintenance impossibility.
Right, right and that's you know that's because that is a good beginner question of well why have third party packages why not have everything in there and it's it's just too much to manage too many maintainers and um
yeah and too much complication like there comes a batteries included is all very well but kitchen sink included well there comes a point where if it's not suitable for your project why do you need it?
And this is on the that continuum again between micro frameworks and more full featured frameworks.
And hopefully Django hits something of a sweet spot in that it's batteries including it's got the core and then with the ecosystem as well it's got all the other things you want and it's extensible too.
So when I sort of tell people you know what is Django and why should you use Django you know the the big points I sort of hit is look it's it's really popular.
It's been around for a while it's used by some of the biggest websites in the world like Instagram is probably the most prominent example.
Pinterest yeah well yeah I don't know yeah I think Pinterest maybe moved off.
You know when you get to a certain size you know everything kind of gets custom but you know a huge one is it's built in in Python which Python is a great choice for learning how to program and so if you're new to programming and you want to build a website you know Django is a great choice for you.
You know you should always just like you should learn multiple programming languages you should learn multiple web frameworks.
But if you have to pick one starting out I think Django is a great choice.
And again it's just like the Python programming language it's scalable.
You can get up and going but you can also use it on the biggest sites in the world and that's not a common feat for many technologies that they can span that spectrum.
Yeah yeah something like that.
I mean you know the the the story for beginners is certainly compelling but also the story for to keep going with it.
Why how why haven't I abandoned it for something else?
Yeah you know over the years I've used multiple frameworks in multiple languages and why do I stick with Django?
Because ultimately when I come to write a website it's got all the tools I need.
Yeah and we haven't even touched upon you know API support which you know Django is extremely strong with and in some ways that's probably what more you know intermediate advanced level people come to Django you know come to Django for if they haven't already used it is they say right I need to build a RESTful API look around and you know with Django REST framework um you get a very Django like approach which is not common with many um API frameworks.
Yes and then so you spend a few years writing writing APIs using Django Rest framework and then you come back and you think actually the re the rest of Django is exactly what I need for building the the rest of the site around it.
Yeah yeah it would be I'd be I'd be curious how many people you know what the progression is if people you know jump into Django Rest framework.
I mean I think generally I think APIs are a next stage after you build uh websites in some fashion but to have you know if I had to guess
if I had to guess on that I would say that people build some basic websites using say Django just as a when they're learning and then they get they find themselves in a professional situation where they're writing an actual application and all of us they're all they're immediately writing APIs.
Yeah that's the thing that when people are learning you know it's yeah most Django developers in a professional context as you say are folk are probably writing APIs and and yet you know if you were going to build a full stack you know so dedicated back end front end application as a solo um you know engineer that's that's quite a challenge.
It doesn't make quite as much sense but in in any company setting you're going to be um you're gonna be focusing and very specific in your in your what you're doing day to day anyways.
Yeah I mean there's a difference between a side project that you're writing by yourself and then something you're doing in a bigger company.
If you're if you're working on Django in a bigger company almost certainly using REST framework and then they've got front end engineers which are using React or Vue or you know whatever this week's hotness is.
Yeah yeah but that is that you know when people are learning you know it's like okay I want to learn how to program.
All right we'll learn how to build static sites with HTML and CSS and now sprinkle in JavaScript and now learn about you know databases and user authentication and security
an on the way bash and
yeah yeah yeah command line right yeah and then okay great I'll use Django you know because I have this people read my books and like yay and they're like wait what's what's the APIs?
It's like oh yeah well actually you're probably writing APIs with it and then they write that and they're like oh great and it's like oh well now I need to learn a front end um framework.
So there is a degree to which you sort of go oh my God um but you do I think you can rem you know with practice you can remove yourself and say right these are how the pieces fit together and you can't master them all but you can play around with them in a professional setting you will generally focus a bit your skills um and you know to to plug Django again Django is kind of there for you all the way through and if you've used Django and then you switch to something else you're gonna be spoiled.
Yeah I mean again
unless it's unless it's Rails which has a you know different similar idea you're used to batteries included but customizable and then you have to just do all the guts yourself.
It just takes so much time.
And yeah and as well I think the other the the the other way of looking at it in in the context of the wider technology where you've this front end frameworks this DevOps stuff there's databases there's search engines there's there's all these tools Django by focusing on Django which makes a lot of the decisions for you you keep the surface area of what you need to know for that component that back end web application component as smaller than it would otherwise be.
Yeah the actual code that you were writing is um very very concise
and the things you have to know you don't have to know all the surrounding ecosystem packages you don't have to know all these details because Django's made those decisions for you.
Yeah right that's why I think most micro frameworks are much more suitable to advanced users rather than someone intermediate level.
Yeah I think that's yeah I mean yeah I couldn't I for beginner advanced beginner even competent people I wouldn't recommend micro frameworks because I I think you're making the job too hard for yourself.
Sure if you want when you're an expert you do what you want.
Yeah well and you know like all good advice I mean what I find is I I I tell people that um they sometimes don't listen they go off and then they get stuck with a micro framework and then come back and say oh you were you know you were right.
Yeah but that's learning too that's part of learning that's fine.
Yeah but people that's that's part of the life experience.
Yeah if you're with a micro framework and you're feeling really stuck and confused by all the third party packages try something like Django and see how that goes for you.
Yeah and like but like whenever you try anything you have to give it time.
There's no like you know I oh I did I did I tried Flask for a day and didn't like it.
I tried Django for a day.
I didn't no things take longer than that.
So you have to give everything its its due.
Deep thoughts.
Well, you know.
All right.
So what anything else we want to mention before we wrap up?
No, like um
well, there's you know, this is one of the early episodes.
There's so many more areas we're going to talk about.
So if you have feedback, please let us know.
Um, you can go to our website, DjangoChat.com, and if if there are topics you want us to discuss, you can suggest them.
Um, we have a lot of things we're gonna talk about, but let us know.
Yeah.
Ping us on Twitter at chatdjango chatjango.
All right, we'll see you next time.
Bye bye.