How I learnt Django
About me
I am a Python developer and I love writing and building awesome stuff for people to use.
This is a quick post for newbies about to dive into Django, here I'll give short summaries of my experience in learning Django and tips/advice on how to work with Django.
Why I wanted to learn Django
After learning python, I went straight for Django because at the time it was the popular framework for building web applications with python. I liked the fact that it had so many utilities to help ease web development.
The tutorials on learning Django were much on the internet, that was a good sign to me because if I had any issue on Django, I could easily search it up on Google or find a solution on Stackoverflow.
How I approached learning Django
I started with YouTube videos, Online articles and Stackoverflow.
I first got into views and URL routing on Django, I had to understand how the server sends the HTML page to the browser and what the different URL patterns,parameters and routing meant in relation to the view function.
Understanding this flow made me know how parameters could be gotten from URLs, how I could send any kind of response and also how to handle cookie data and csrf tokens.
Next, I entered the Django model, since this section dealt with a database, I had to take introductory tutorials to how SQL works so I won't be lost in the Django tutorial, I learnt how ORMs simplify the process of writing SQL queries and running this queries against the database, then I went into what migrations do in Django.
I learnt of Middlewares and how you could use them to wrap over requests and perform actions before these requests went to the next middleware.
Finally I learnt of Celery and Redis and how they work together in handling tasks and caching results respectively...
Once I was through with the basics I did 2 major projects that covered all these areas.
Challenges I faced
Generic Views and Mixins
Using the basic django views to perform actions is great, but as a newbie in the system I looked at the Generic views individually and did not know what was going on, due to the multiple inheritance and abstract conditions I had to meet for the view function to work. The same as the mixins,the inheritance level was confusing to deal with because I wanted to know what was going on.
Template errors
This was a major road block, because I did not know that templates are evaluated before values are injected and served to the browser, so simple errors like block tag error, URL routing errors hindered my progress greatly till I figured it out.
Database and Migration Errors.
The Django ORM directly maps to how your database would look like so changes to your database would be reflected when doing migrations on django..
I was faced with several situations when one migration file did not correspond with the previous file or certain fields were deleted in the migration but I called them in the view function and this resulted in serious bugs I could not solve for days.
In situations I would make new migrations and new errors I've never dealt with keep popping up because i did not fully understand how migrations in django worked.
Key takeaways
Django is a powerful web framework enabling programmers with a fast and clean pathway to quickly building applications without thinking of the specifics, but sometimes these specifics are needed to fully understand how Django works too...
Tips and advice
-
If you are confused Google it!
-
Always read and use the Django documentation
-
Always draw a flowchart or diagram on how you would like to achieve a project.
-
Build projects, this is the best way of applying all the concepts you've gathered through tutorials.
-
Understand Migrations before playing with your database fields.
-
Generic views are Abstractions, you don't need to dive into the multiple inheritance classes and know what every function does, just use the functions given to you for that view function.
Final thoughts and next steps
I love Django and the freedom it gives me as a python developer, its definitely hard to understand and use at first, but once you can get all the basics in, it's worth using.
Thank you for going through this article and have a nice day. ❤