Flux IT Thoughts
Published in

Flux IT Thoughts

What You Need to Know before Using Django

In this article, I try to provide a more complete picture of the pros and cons of this Python framework, and to justify why it is worth learning Django within an ecosystem where JS predominates.

Django is a web framework designed to quickly develop apps. It is written in Python, and it already possesses a large number of users that keeps growing non-stop. Originally, it aimed at making website development processes easier, putting the emphasis on the DRY (Don’t Repeat Yourself) principle.

But first, I should tell you a little bit more about what led me to write with it. And to do that, I must start by telling you that I am a self-educated student and that, in addition, before programming, I used to knit Amigurumis for a living. That is to say that I had absolutely no idea what a server or request was, and a bunch of other words seemed foreign to me.

During the pandemic, partially motivated by the desire to occupy my free time, I started browsing HTML, and it was the beginning of something that would never end (those of you who chose the same path know what I am talking about).

There were bumps in the road; at first, everything seemed odd and incomprehensible to me, but I was lucky enough to have met a community full of loving and patient people. They were the ones who helped me stay on this path and not give up.

During this journey, I discovered Django, but I still didn’t quite understand many programming basics. But thanks to Django’s community, documentation and tutorials, little by little, everything became clearer to me. In addition, since it is one of the most used frameworks, it made it possible for me to get my first IT job.

Now, I share with you my conclusions about my Django journey.

PROS

1. ORM

One of the most important features of Django is its ORM which gives you a database-abstraction API that allows you to create, retrieve, update and delete objects. It is quite intuitive to use, and it covers almost every common SQL query.

Basic SQL/ORM queries:

With ORM, creating a database table is as simple as creating a class with model inheritance. Model and Django will take care of the rest.

It also supports multiple databases, so switching from one engine to the other (Postgres, MySQL, etc.) is quite simple. You can easily do so by making some changes to Django’s settings.

The fact that you can only access data through the objects attribute, instead of doing it so directly from the Model class, makes Django more complex than other frameworks like Ruby on Rails which allows you to make the same query in a shorter and easier way.

Although this actually works, it becomes complicated when you need to write more complex queries or when you need to add custom methods to our class, in which case, Django provides the Manager class. But this only adds another abstraction layer which makes the code harder to read.

Ruby on Rails vs Django.

2. Django admin

A dynamic admin interface which easily performs CRUD operations in the database is included by default.

The Django admin interface reads metadata from your models to provide a quick, model-centric interface where trusted users can manage content on your site. Also, Django relies on a through permission system to restrict access to data depending on the administrator’s needs.

The admin’s recommended use is limited to an organization’s internal management tool. It’s not intended for building your entire front end around.

3. Authentication system

Another advantage of using Django is that it has a field-proven authentication system which identifies different logins by means of a cookie that is used on different websites with high data traffic (such as Instagram or NASA’s website).

In addition to using login authentication by means of a cookie, there are packages that allow you to use it with JWT.

4. Permissions system

Django comes with a built-in permissions and groups system which links users to database models. It provides a way to assign permissions to specific users and groups of users.

This is a very useful feature, and it prevents you from writing extra code lines, since every time you make migrations and models are created, Django automatically creates four permissions for that object (add, change, delete and view).

In addition, the User model has a many-to-many relationship with Permissions and Groups models which are responsible for saving the previous permissions.

With Django, it is very simple to establish, delete and examine user permissions.

From Django’s admin interface or Python’s terminal, you can easily organize, assign, remove or create customized permissions for specific groups.

5. Multiple packages

Thanks to Python’s large community, Django has several packages which are monitored and improved every day. These packages aim at solving many common problems such as the creation of APIs, the handling of permissions and authentication, etc. Some of the most used ones are:

  • DRF (Django Rest framework)
  • Django-rest-auth (authentication)
  • Django-filter (searches)

CONS

1. Monolith:

Django also has a lot of functions and features for web app development, an ORM, a template system, middleware, among other features that you may never use or need.

2. Execution Speed:

There are faster options nowadays. This can be a disadvantage if you are only looking for speed. But this is not a fair comparison, since FastAPI, for example, only focuses on creating APIs in a simple and efficient way, while Django is a complete solution that offers other features that FastAPI does not have.

3. Learning curve:

Having so many features is very useful when it comes to reducing code lines, but it becomes a disadvantage when it comes to learning how to use them all.

If we compare this framework to other frameworks, such as Flask or Express, it takes much more time to efficiently learn how to use Django’s features (such as ORM, middleware, views, handling of URLs, among others) than other frameworks’ features.

TLDR:

For all these reasons, I think that Django is a very good option to learn how to use a backend framework. Django will help you develop complex websites in a short period of time and understand how each process works.

Even though the learning curve is slow (as I have mentioned before), documentation is very clear, it provides examples and tutorials ranging from the basics to advanced cases, and you can resort to this information when you have doubts or do not know how to continue.

I hope this article will be helpful and inspiring to others who, just like me, are seeking a path in programming.

Websites that Use Django:

  • Instagram.
  • The New York Times.
  • Pinterest.
  • Nasa Science.
  • Disqus.
  • Mercedes-Benz.
  • Orange.ch.
  • National Geographic.

Useful Websites:

https://www.djangoproject.com/

https://djangogirls.org/es/

https://developer.mozilla.org/es/docs/Learn/Server-side/Django

https://djangochat.com/

https://adamj.eu/tech/2019/04/03/django-versus-flask-with-single-file-applications/

https://www.freecodecamp.org/espanol/news/para-que-se-utiliza-django-de-python-5-razones-claves-por-las-que-uso-el-framework-django-para-proyectos/

https://djangopackages.org/

https://forum.djangoproject.com/

https://djangochat.com/

Know more about Flux IT: Website · Instagram · LinkedIn · Twitter · Dribbble · Breezy

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store