Hello everyone, I am Tairu and I would love to introduce you to the love of my life. She is beautiful, she has perfect curves but my favorite is her smile. One thing I love about her is the fact that she knows how to get things done.
Her name is ..... Django ๐
Yeah, I am in love with Django so I am off the streets ๐คฃ.
A lot of us have a crush on her too, and I am here to give you some tips on how to get her attention and make her all yours ๐.
switches to being serious
I have gathered a list of tips I believe would help upcoming django developers build better django apps while also understanding what they are building.
DISCLAIMER
These are my opinions and it's fine if you do not accept them or think they are necessary.
Now let's GOOO
1.Get used to building everything from scratch at first
I usually advice beginners to ignore using most of the batteries django comes with and build without them.
Examples are the default registration page and login page which handles everything for you. All you are needed to do is to import the views, route them to a url pattern (in your urls.py) and use.
Using too many batteries at the beginning of your learning process would make you ignore the key concepts behind the whole process.
E.g Login process needs you to collect the username and password, authenticate using the 'authenticate' function and check if the user exists or not before you login using the 'login' function
from django.contrib.auth import login, authenticate
Try to build things from scratch without using too many batteries till you get very comfortable and you understand the whole flow and concept behind it.
2.Start with Function Based Views Before Class Based Views
Using Class based views feel like heaven especially when you are to do the most basic of things. I mean all I need to do to render a page showing a list of queryset from a model instance is this
from django.views.generic.list import ListView
from articles.models import Article
class ArticleListView(ListView):
model = Article
SEXY!!!!
'but I do not know how it helps with returning a list but it works' - Nah, don't do that.
I believe you should only begin to use Class based views after you feel very comfortable building with function based views. Just like I said in number 1, building from scratch at first so you would understand the whole logic behind most of the things Django has for you.
3.Learn about using a Custom User Model
Django comes with its own default User model, all you need to do is import and use but sometimes you want to add extra fields to a user model like username, date of birth, etc.
Many tutorials would prefer creating another model which would have a one to one relationship with the default user model (and maybe call it 'Profile' or 'UserProfile').
I believe its easier when you have to interact with just one model which you could make changes to directly.
4.Try playing with Postgres and throw away your db.sqlite3
I personally had issues using postgres with django the first time I tried but it is actually very easy.
Truth is Postgres is a better option to use over db.sqlite3 and learning to set it up on your local pc and integrating it with your django app is a good one.
5.Keep Building, Build a couple of apps that involves template rendering
The dream of many django beginners is to a become Back-end Engineer. Back-end Engineers build API endpoints so they do not render templates.
Making sure you are very comfortable with building rendered template apps before learning to build API endpoints with Django makes things far much easier when you start building API Endpoints.
Basically, it is almost the same process with the only difference being that you return JSON object instead of HTML pages when you build API endpoints with django.
6.Comfortable with rendering templates?? Pick up Django Rest Framework
Django Rest Framework is a framework used to build Rest API endpoints with Django.
So you can build a server side app using using Django Rest framework and watch a React App or Android app communicate with your django app (COOL!! ๐ฏ).
I would recommend using the tutorials on their website to learn how to build API endpoints with Django Rest Framework.
The Tutorial doesn't have everything so you need to keep reading the Django-Rest-Framework (DRF) documentation/API Guide to keep learning about DRF.
Link to the tutorial : DRF Tutorial
Link to the DRF Homepage: DRF Homepage
Conclusion
Django is a wonderful framework and it can do wonderful things. It's best to understand what actually makes some functions work. You can even try to read some of the code that runs django itself to know how some methods and classes work as this would help you use those methods or classes better and maybe one day you get to contribute to Django itself.
I hope you have fun building.
Tay.