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 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 going to dive into
that today. So Carlton, when someone asks you, what is Django? What do you say?
Oh, right. Good question. Right. So Django is 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
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
enabling you to build your web application that serves those responses so um there's a view layer
there's a template layer there's an ORM these are bits of the Django that you wouldn't you don't
want to create from scratch um right that'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 python has flask and django and i guess within that there's different philosophies
of how you build a web framework but yeah it's a 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 i mean you know the tagline is the web framework for perfectionist with the
deadline so the idea is you want to do it right but you've got to do it quickly right yeah and
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. 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 on 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, non-functional.
Exactly. So it's purely, you know, sort of a tool for us developers, but a tool that's awesome and important.
And you'd be, you know, as a learning exercise, it would be interesting to build your own web framework,
but you would quickly, I think, appreciate why 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.
You know, they picked up Perl, they wrote their web framework in Perl.
picked up php they wrote their own web and you had all these homebrew web frameworks around and
yeah they all had problems and you know 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 Gatsby and then look at it.
You know, it's not quite what I want.
I'm just going to 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, oh, this is kind of actually harder than I thought.
Maybe I'll just use.
In a way, it's easier to write a static site generator than it is to read the docs of a static site generator and work out how it works.
Yes, true.
Right.
So Django is a web framework.
It's a set of tools to automate what 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.
There's a couple of 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.
You know, I think a big, within the web frameworks, there's sort of, if you can make a distinction, there's micro frameworks like Flask, where you have lots of, you know, it's like a manual car.
Or you have ones like Django, which are full-bodied, batteries included.
It's more like an automatic.
So do you lose a little bit of control?
Yes.
But you don't, you know, that's not even, it's more, you know, David Hennemeyer Hansen of Ruby on Rails described it as the difference between a bag of Legos.
you dump on the floor that's a micro framework and a truck that just works you know so um we'll do
we'll probably do a separate episode on that but 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 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 Django and Rails in particular,
they go for the batteries included approach.
So they provide you not everything you need,
but 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 a micro-framework from the beginning,
you're going to have to install half a dozen, dozen third-party packages
just for a basic blog site because it's just not included.
So different philosophies.
Yeah, there's nothing wrong with that depending on your application.
I mean, we're clearly biased, but many people are biased as we are.
And I mean, it really it depends on what you need.
It depends on the context.
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 right for me i can get right down to the view layer and i know it well
so there are 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
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 we 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 try to ask,
well, what exactly do you want?
If you're, 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.
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.
The whole data science and data analysis and Jupyter Notebooks.
I know that you can use JavaScript in Jupyter Notebooks,
but it's Python-based and the whole Pandas project and all of that.
Python is very practical in the real world.
Right. Yeah.
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 don't, exactly as we were just talking about,
they don't know the ins and outs of the Flask ecosystem.
And I think, you know, when you start out,
the Hello World with Flask is simpler than Django.
So I think 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 Flask is sort of either end of the spectrum and Django is more in the middle.
And again, you should learn both, but Django is a great choice for someone who wants to learn web development.
But part of the challenge, and I've 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 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, 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.
But, you know, I personally, I like the ability to just get something done and then backfill rather than have to spend huge amounts of time up front.
Yeah, I mean, I think people aren't, 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 the great thing with, like, the Django tutorials or whatever is 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 you can edit, and you can, you know, users can filter by tags and all these great stuff.
And you haven't really understood all of it, but you've got 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 Python is a good beginner language choice, but also used at the highest levels, Django as well kind of can span that spectrum for you.
So what else should we say? I mean, there's so much, you know, 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.
I mean, I guess another, you know, in terms of, you know, what is Django? Why is Django special?
You know, it was built from the beginning with this, you know, for perfectionists on a deadline, this idea of you should be able to work quickly on things, you know, and part of that is some of the maybe extra features that not every web framework has is, so the admin is a huge one.
So this is right, the admin. So it was built for a newspaper company, right? And they had two or three publications, and they had the development team who were building 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.
So you define some models, which are part of 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.
It's got permissions involved with it.
It's super.
And to get that out of the box for essentially zero effort
but 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, you know, at all levels,
to have a graphical interface way to interact with the guts is very powerful.
So you can also go into the Django shell,
so that's like a command line view, 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, you know, when I teach total beginners,
I don't drop into the Django shell at all,
but, 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, 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, need a way to look at the business people, marketing sales, to look at the data.
And there's lots of Django conversations.
comes with that out of the box, which is a super strong feature.
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, that's the core of almost every website.
Django really handles that in an elegant way, I would say, in terms of you can get up and running quickly,
but you also can customize it, and all the security stuff is very well handled.
Well, like the input validation and, you know.
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, you know,
and we should mention them among your other projects.
You are now in Maintain Django Crispy Forms,
which is an add-on to.
Yeah, so that's good.
Like, I don't know, you might want to have,
say you've got a model field, which isn't part of the form.
It enables you to create a nice form layout,
So you've got like the form fields that you want editable and then a few model fields and then some more form fields.
It's kind of cool for defining model fields and form layouts, which are non-standard.
It makes it into a nice programmatic interface.
So it's a good package.
Yeah.
And that's, you know, I guess the next point, that's an example of a third party package, which there are many with Django.
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 enhance or customize a built-in feature
or you can have additional functionality that isn't in Django itself
because it doesn't need to be or there's a lot to maintain with Django as is.
But there's a Django packages website we'll link to.
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 for almost anything you can think of,
there's a third-party package out that implements it,
and either it's well-maintained 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 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 know, Django is not a shiny new toy anymore, but it's still being actively worked on and improved.
And that's really valuable when you're actually have some experience and get burned by, 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 build a company or and, you know, have some stability there?
or do you want to just play around?
And so, you know, 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 mature.
And that means that you don't have to worry
that the new version has broken your entire site
and that you're going to have to restructure everything
and then you're going to end up on an unsupportive version.
You know, we're on version 2.2, we're going to be on version 3 this year.
Those big numbers, they mean something.
It's not 0.something something.
Right, and that's something that, 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.
I think it makes it really exciting.
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, this is another trap for engineers is how much do you want to work on the plumbing versus the special sauce?
And 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 want to focus on something that differentiates it in some way.
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.
That's not going to work.
You've got to be somewhat conservative in your technology choices.
If you're always on the latest database, always on the latest web framework, always on the latest front-end framework, you're never going to get anything built.
Right, right.
But yeah, you need to stay current.
And we'll do a separate episode on Django versions and talk about the Django roadmap for changes.
But it is advancing and also well thought out.
So if you're using Django, you can stay up to date.
What else?
Testing.
So this is one, looking at you, JavaScript, that Django has its own tests and also takes advantage of Python's built-in tests.
And tests are 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 not every web framework does?
Well, there's two parts to it.
One is the web framework itself, well-tested, and Django is.
And 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, sort of...
I guess the last big thing I would say is
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.
But Django gives you built-in options, but it's also very customizable.
And I think that's a good choice that it makes,
but that's sort of the last major component of any web framework
because you need to have some sort of user registration.
And there's things like social authentication, two-factor.
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 people to be able to create user accounts
or give them user accounts,
and then you want 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?
Yeah, and you can set all the...
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, if you want Facebook login,
there's third-party apps for that.
And if you want two-factor auth,
there's third-party for that.
You know, this is where the ecosystem is great.
There's the foundation and then the surrounding things
which add on all the extras would be impossible.
It would make, you know,
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 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
you need it and this is on that continuum again between micro frameworks and more full-featured
frameworks and hopefully django hits something of a sweet spot and its 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 it's probably the
most prominent example.
Pinterest, I mean.
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 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, something like that.
I mean, you know, the story for beginners is certainly compelling,
but also the story to keep going with it.
Why haven't I abandoned it for something else?
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 API support, which Django is extremely strong with.
And in some ways, that's probably what more intermediate, advanced-level people come to Django for,
if they haven't already used it, is they say, right, I need to build a RESTful API, look around.
You know, with Django REST Framework, you get a very Django-like approach, which is not common with many API frameworks.
Yes, and then so you spend a few years writing APIs using Django REST Framework, and then you come back and you think, actually, the rest of Django is exactly what I need for building the rest of the site around it.
Yeah, yeah, 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've built 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 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 most Django developers in a professional context, as you say,
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 going to 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.
And on the way, learn Bash and...
Yeah, yeah, yeah, command line, right, yeah.
And then, okay, great, I'll use Django, you know,
because I have these people read my books and like, yay. And they're like, wait, 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
framework. So there is a degree to which you sort of go, oh my God. But you do, I think you can,
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'll generally focus a bit your skills um and you know 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 going to be spoiled um 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 other way of looking at it in the context of the wider technology where you
there's front-end frameworks there's 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
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 think you're making the job too hard for yourself.
Sure, when you're an expert, you do what you want.
Yeah, well, like all good advice,
what I find is I tell people that 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 right.
Yeah, but that's learning too.
That's part of learning.
That's fine.
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
whenever you try anything, you have to give it
time. There's no but like, you know,
I tried Flask for a day
and didn't like it. I tried Django for a day.
No, things take longer than that.
So you have to give everything its due.
Deep thoughts. Well, you know.
Alright, so anything else we want to mention
before we wrap up? No, like
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 jango chat.com and if there are topics you want us to
discuss you can suggest them um we have a lot of things we're going to talk about but let us know
yeah ping us on twitter at chat jango chat jango all right we'll see you next time bye