DEV Community

Cover image for 5 lezioni che ho imparato con Django (che nessuno dice) | 5 lessons I learned with Django (no one tells you)
Roberto Celano
Roberto Celano

Posted on

5 lezioni che ho imparato con Django (che nessuno dice) | 5 lessons I learned with Django (no one tells you)

Introduzione | Introduction

Italiano: Questo articolo è disponibile sia in italiano che in inglese. Scrolla verso il basso per la versione in inglese.

English: This article is available in both Italian and English. Scroll down for the English version.


🇮🇹 Italiano

Quando ho iniziato a studiare Django venivo da un background classico PHP/MySQL, e all’inizio ho pensato: "Va bene, è solo un altro framework." Poi ho capito quanto fosse diverso l’approccio di Django. In questo post voglio condividere 5 cose che ho imparato studiandolo da zero, che potrebbero essere utili a chi si avvicina per la prima volta a questo potente framework.


1. Il sistema delle migrazioni è potente, ma va capito

All'inizio pensavo che bastasse modificare un modello e lanciare makemigrations + migrate per sistemare tutto. In realtà, se non si ha chiaro come funzionano le migrazioni, si rischia di compromettere la struttura del database. Ho imparato a non sottovalutare il comando showmigrations e a usare con attenzione --fake.


2. Le view non sono controller: sono più flessibili (ma serve disciplina)

In Django non esistono veri controller come in altri framework MVC. Le view possono essere funzioni o classi, e questa libertà è un’arma a doppio taglio: puoi fare quasi tutto, ma se non sei ordinato diventa un caos. Ho iniziato a usare le CBV (Class-Based Views) solo dopo aver capito bene le FBV (Function-Based Views).


3. Il sistema di template è semplice... finché non ti servono cose complesse

Il template engine di Django è chiaro, ma appena vuoi fare qualcosa di più dinamico (cicli annidati, logica condizionale complessa), capisci che non è pensato per “pensare troppo”. Django ti spinge a mantenere la logica nel backend e non nel template. Una scelta saggia, seppur limitante.


4. La shell interattiva è la tua migliore amica

python manage.py shell è uno strumento potentissimo per testare rapidamente modelli, query e oggetti. All’inizio la ignoravo, ma poi l’ho usata per risolvere bug, capire il comportamento dei manager, e fare esperimenti con i dati. È come avere un laboratorio sempre a disposizione.


5. L’admin è magico, ma non è la tua dashboard

L’admin di Django è fenomenale per il debug e la gestione veloce dei dati, ma non è pensato per l’utente finale. All’inizio volevo usarlo come “backend admin”, ma poi ho capito che per il pannello vero serve una dashboard personalizzata.


🎯 Conclusione

Studiare Django è stato più che imparare un framework: è stato cambiare mentalità. Django impone ordine, struttura, e un modo preciso di pensare al backend. È stato difficile all’inizio, ma ora non ne farei a meno.

Se stai iniziando, il mio consiglio è: non saltare i concetti base, soprattutto modelli, migrazioni e view. Ti ringrazierai più avanti.


🇬🇧 English

When I started studying Django, I came from a classic PHP/MySQL background, and at first I thought, "Alright, just another framework." Then I realized how different Django's philosophy is. In this post I’ll share 5 things I learned while studying Django from scratch, which might help anyone starting out with this powerful framework.


1. The migration system is powerful, but you need to understand it

At first, I thought modifying a model and running makemigrations + migrate would fix everything. In reality, if you don’t understand how migrations work, you can mess up your database structure. I learned not to underestimate showmigrations and to use --fake cautiously.


2. Views are not controllers: they’re flexible (but require discipline)

Django doesn’t have traditional controllers like other MVC frameworks. Views can be functions or classes, which gives you flexibility — but also chaos if you’re not disciplined. I only started using Class-Based Views (CBVs) after understanding Function-Based Views (FBVs) well.


3. The template system is simple... until you need complex logic

Django’s template engine is clear, but as soon as you want to do nested loops or advanced conditions, you realize it’s not built for “heavy thinking.” Django encourages you to keep logic in the backend, which is wise, though sometimes limiting.


4. The interactive shell is your best friend

python manage.py shell is a powerful tool to test models, queries, and objects quickly. I ignored it at first, but later used it to fix bugs, explore model behavior, and experiment with data. It’s like having a lab at your fingertips.


5. The admin is magical, but it’s not your dashboard

Django’s admin is great for debugging and quick data management, but it’s not designed for end users. At first I wanted to use it as an “admin panel,” but eventually realized you need a custom dashboard for that.


🎯 Conclusion

Studying Django wasn’t just about learning a framework — it was a mindset shift. Django enforces order, structure, and a precise way of thinking about the backend. It was tough at first, but now I wouldn’t go back.

If you’re starting out, my advice is: don’t skip the fundamentals, especially models, migrations, and views. Your future self will thank you.


Traduzione:

Questo articolo è stato tradotto con l'ausilio di strumenti di traduzione professionali.

This article was translated with the help of professional translation tools.

Top comments (4)

Collapse
 
solvecomputerscience profile image
Solve Computer Science

Con Django è facile perdersi perchè gestisce molte cose. Ci sono framework alternativi che consentono uno sviluppo più API-oriented ma che non hanno strumenti tipo l'admin e i template, per esempio. Secondo me con FastAPI si lavora molto bene.

Collapse
 
roberto_celano profile image
Roberto Celano

Hai perfettamente ragione, Django gestisce molte cose "out of the box", e all’inizio può essere un po’ dispersivo.
Ho trovato utile abbracciare il suo approccio "opinionated", ma capisco chi preferisce qualcosa di più snello e focalizzato come FastAPI, soprattutto per progetti API-first.

Grazie per il commento! Potrei approfondire FastAPI come prossimo step 😄

Collapse
 
solvecomputerscience profile image
Solve Computer Science

Attenzione alla scelta del DB: Django fa tutto, con FastAPI è un extra (vedi SQLModel, ma fare le migrazioni è un po' difficile)...

Thread Thread
 
roberto_celano profile image
Roberto Celano

Hai fatto benissimo a sottolinearlo!
Con Django mi sono abituato ad avere tutto integrato (ORM, admin, template, ecc.), e capisco che con FastAPI si entra più in un’ottica "componibile".
Grazie per la dritta su SQLModel — terrò d’occhio anche Alembic per le migrazioni, anche se so che non è sempre semplicissimo.