I started learning how to program Django about 6 years ago…
When I left college with a degree in Computer Science, I knew I had to go get a job somewhere, anywhere. I finally got a job at a non-profit using PHP to create web applications. I didn’t know PHP when I began. I started with a tutorial. I bought a copy of a book that I still have called PHP Solutions: Dynamic Web Design Made Easy.
But I had a job! I couldn’t just do tutorial after tutorial until I was completely 100% ready. Who knows how long that is going to take? I need to get to work NOW.
What I learned trying to build web applications using PHP is the same process that I used to learn how to build web applications using Django.
I knew Python pretty well. I was already using it for automated scripts amongst other things. Python became my go-to for most of non-web app coding so I figured I would try to port all the web applications that I created to Django instead of PHP. However, I needed to learn Django.
What I learned is Django is a complete paradigm shift from the likes of PHP and other web languages. So, I needed to use what I learned from PHP as a starting point to learn Django as quickly as possible. This was pretty tough and I thought it would take far too long to learn…
What I did isn’t spectacular… you can do it too!
You’re here because you want to learn Django. Either you’re trying to learn something new on the side, or you are trying to change careers or maybe like me, you are about to port all your web applications to Django and you need to learn to use Django as quickly as possible.
The problem with how most people learn Django or anything else is that they don’t take off the training wheels. They keep looking for the next tutorial or the “best” class or a “best” blog post. Hopefully, one of these tutorials is going to work better than the last one. It’s very hard to get everything straight so you try to buy a new book or that new course on Udemy.
This is not the right way to learn Django. This is the slowest way to learn Django. And hear me out, I’m not saying that tutorials are bad. Token Authentication by Example is a tutorial. I’m saying, tutorials are hand holders. They are training wheels for the learning process. Just like you can’t learn to stay up on a bike with training wheels, you also can’t learn to make web applications in Django without putting down the tutorial.
And you CAN do this. And you’re going to learn how to learn Django in 3 months or less. Are you ready?
How I learned Django in 3 months by creating a web application and put down the tutorial…
I get it. I’m basically writing a tutorial on how to stop using tutorials. That’s really kind of weird. But, this information is incredibly important. The ONLY way to get better at your craft is to do a TINY bit of something, then check your results. Do a little bit more, then check your results. This is the ONLY way. You will never learn EVERYTHING from a tutorial. You need your own experience.
Here are the steps that I took to learn Django in 3 months AND at the end of the 3 months I had an ACTUAL web application that the non-profit that I was working for at the time loved and paid me for. So, let’s get started. Remember, instruction (i.e. type this, then type this, then do this.) is ONLY good for 1 thing. To get a bird’s eye view of the technology as quickly as possible. After that, you need to learn to read the documentation and try things yourself using trial and error and Test Driven Development (or: quick feedback loops so that you can learn as quickly as possible).
Tiny and quick feedback loops is the secret to success…
The secret to learning Django is to create tiny and extremely quick feedback loops. You can do this with either Test Driven Development (if you’re planning on putting the web app out in the public) or you can do this with very, very tiny actionable tasks then testing that the task actually did what you wanted it to do.
For example, let’s say you want to start with your models. I would start out with something like this:
That’s literally all I might write. Then, because I started out with the Official Django Tutorial (remember, bird’s eye view), I know that I have to run
./manage.py makemigrations and
./manage.py migrate for the new database table to actually get created.
Then, I’ll add a couple fields, just to see what happens:
Then, I’ll do another
migrate. Then, I’ll see what happens.
Then, I’ll go into
./manage.py shell and I’ll import the
Comment model and run some ORM commands to create some
Oops. I get an error. What does this
NOT NULL constraint?. Well, it failed on
comment_comment.created. I created a Comment and made the
NULL. So, I can deduce by the error that Django doesn’t like
NULL fields unless you specify that they are ALLOWED to be
Hmmm… How can fix this? First, I go to Google and I run a search. “making fields optional in Django models”. I click a few links and I learn that in order to fix the error, I need to add
null=True to the
migrate again, I go back into the shell and try again.
Sweet! It worked! However, I want the
created field to be created every time I create a new
Comment. How does this work? I go back to Google and search “automatically save datetimefield in django”. I learn about
auto_now_add. Then, I try it and I discover that every time I create a
Comment now, the
created field automatically populates.
As you can see, I start with something, then I test it. Then, I want to see if it’s possible to do something, I search Google to the best of my ability and click a few links and read, implement and test again until something works. I read errors to the best of my ability by determining where it says I should go look, then I play around with code on that line until I fix it. Then, I move on.
What is the smallest thing you can do that will get you closer to something better?
This is a question that you need to constantly ask yourself. When you’re first starting out, the smallest thing you can do is the Official Django Tutorial. This will give you a very, very basic bird’s eye view of what you can do with Django. The next thing you can do, decide on an application. Maybe it’s one that you’re already working on. Or, it could be a personal one like a blog. It should be something completely different than the Polls app that you created in the tutorial.
Next, figure out what you need to create that application. Let’s take a blog.
Here’s what you need:
That’s an extremely simple blog, but you really need to think SIMPLE in order to just start. Otherwise, you’re going to lose the motivation to proceed.
Your goal is to break those 3 things into the following:
- Models (Database tables)
- Views (actions on the models themselves – retrieve all, edit, create)
- Templates (index templates, edit templates, create templates)
Breaking the objects into models is pretty simple. These are your models:
- User (this is already created in the Django Framework)
Next, you need to think about the actions that you are going to take on each of the models.
- As a user of the system, you can GET ALL of the Posts
- As a user of the system, you can CREATE a Post
- As a user of the system, you can EDIT a Post
- As a user of the system, you can DELETE a Post
- As a user of the system, you can GET ALL of the Comments for a single Post.
- As a user of the system, you can CREATE a Comment
- As a user of the system, you can EDIT a Comment
- As a user of the system, you can DELETE a Comment
- As a new person, you can SIGN UP as a User
- As a new User, you can LOGIN
- As a logged in User, you can LOGOUT
- As a logged in User, you can DELETE your account.
Each of the following VERBS are actions. You can think of actions as Views. At this point, you don’t really need to have fields in any of the models, but you should have an idea of how the model relationships are going to work:
- A User can own 0 to MANY Posts
- A Post can have 0 to MANY Comments
- A User can have 0 to MANY Comments
You can use this relationship to create the ForeignKeys between each other models. Once you create the relationships within your models, you can then think of all the fields that the models need.
- Posts (Body, Created At)
- Comments (Body, Created At)
- User (Email, Username, Password, First Name, Last Name – remember Django already has this model implemented)
Start with the simplest amount of data that you need RIGHT NOW. Don’t go overboard. Start super small, then when you have something working, then and only then should you expand.
Notice that all these steps are things that you learned from the Official Django Tutorial. What you are doing is applying the things that you learn in a tutorial to something completely different. In this case, you are applying what you learned by creating a Poll Application and applying it to creating a Blog Application. Notice that the Blog is not ENORMOUSLY more complex than a Polls Application. The Blog Application is just SLIGHTLY more complex. This is how to learn the fastest. You simply create something just SLIGHTLY more complex each time you sit at the computer. If you try to implement something far too complex compared to your current abilities, you’re going to lose motivation, you’re not going to be able to finish it without tons of headache. So, don’t bite off more than you can chew.
Apply what you learned and finish the Blog…
Rehash of the tips and tricks above:
- Extremely tiny additions. Do one thing, then test it.
- Break the project down into concrete, actionable steps. Get extremely clear what you need to do to finish the application.
- Read Error messages extremely carefully. Figure out where the problem is. Google the Error messages if you need help interpreting what the Error message is saying.
- Don’t forget to read the Django Documentation.
- Work on things that are only SLIGHTLY harder than what you’re used to. Don’t go overboard.
Use these steps to finish this blog. Send me a Github repository to your implementation and let me help you strengthen your Django skills. It makes it a lot easier to learn Django when you have someone helping you out. If you have any questions or need additional help, email me at email@example.com
What do you want to learn in the next 3 months? Follow my method to learn Django and when you’re ready, learn what to do after following the Official Django Tutorial.