Django : Zen Ready Web Framework

Qrious Kamal
4 min readAug 29, 2023

--

We fall in love with anything that responds with an output in the way we expect. We enter zen state when such request — response cycle continues. Usually zen state is achievable once a skill is mastered or when the number of tasks accomplished increases with every passing moment.

Can Zen State achieved during Learning Phase?

Django framework: Learning Web Dev in Zen State

My intro to Django was through search and exploration. After trying my hands on MVCs Express in Node.js and fluid API creation on FastAPI there were no complete projects that I can showcase in my portfolio. FastAPI did help me in creating the API backend that one can find at https://pyrite-ethereal-soccer.glitch.me/docs & play with it. Its still wasn’t cool.

Dipping my fingers into Flask & Jinja templating language which reminded me of Express. I dumped it after 30 mins of exploration. I seriously thought of the challenges hindering my progress in web-dev. The biggest was the amount of code that I need to type before I can have a working webserver that places some links, pictures on the front end, in a neat way.

Django Automation is for Real: Removes Excess Code

Automation and abstraction go hand in hand. In case of Django abstractions work to reduce the typing you have to do. Starting from creating the files for projects and apps, and populating the configuration of the server, till the positioning of the html tags on the front end using DTL, there are many places Django automates & abstracts. Lets take example of my portfolio site, that is made with my youtube video data.

If you browse the site it contains approx 210 pages. The pages were created from the components like base, headers, footers, and main html parts. There are 5 python scripts, and some 8 or so HTML pages which work together to build the entire site. Django extends the abstraction into HTML front also. These components were stitched with data from the database, pictures stored in servers and the links generated using DTL language. All this leads to very less code, and html pages.

Django Manages User Management: Removes Access Code

Whether its Flask, FastAPI or Express all these frameworks requires the user management, access tokens and registration process to be coded everytime a webapp is created. Which takes time, and complicates things for learners. Integrating it with the entire website, and hosting it on a platform can become challenging too. Django provides User models and admin dashboard as batteries included along with the project. To access the login, registration page the login.html and form in register.html has to be placed in template folder.

Forms & Database Models: Removes Form Creation

Forms solves data collection problem. They get the data from user, and uses it for internal logic or storing the data into database. When the data is going to be directly stored into the database, then Django forms can directly extend the models of the database tables. The html form page is rendered by calling the forms variable from the backend.

When the form is used for collecting info to provide some information back to user, by passing it through views and controller, the request object contains all the information ranging from the User, Method and its associated form action. Each of these can be easily extracted at the views, and logic can be written with ease.

Static & Other DTL Tags : Removes Clutter

Remarkable feature in Django is the STATIC variable that provides access to data or files inside the server hard drive. Doing that through object oriented abstraction makes it possible to use it accross the Django framework. Starting with the settings till the data is rendered on the front-end. Static helps in building the HTML pages from the components parts, by adding the images, css files from folders in static directory.

If the front end needs to be built with two different CSS frameworks, Bulma / Bootstrap… feel free. Since the backend will seemlessly merge with both of them. That too, it can be done with least time and effort. Thanks to Static folders. Managing the code base becomes easier, and controlling the security is a breeze.

Data Loading with Scripts: Removes SQL commands

Data loading is tedious, we all agree. With Django-extensions comes runscript, which executes the scripts that can load data into the database using pythonic loops. Whether it is an integration with BigData or a small CSV files, pythonic loops finally accesses the Database models as Python objects and saves the data. There is no need to write SQL insert query for loading the data. Even the entire database is abstracted as a back-end, since the query to the database is written by Django.

Conclusion : A beginning of Long Term Relationship

We all want to get lost in our work, and create wonderful products and services that are used by millions. If a single user thinks that the developer has cared, and thought about him/her, then it is a huge win. Django makes it possible to create such products.

I have been learning Django and working on different projects including couple of them integrated with AI models, and transformers library. You can find the series of youtube videos here. You can get some ideas here.

https://www.youtube.com/playlist?list=PLbzjzOKeYPCrSLyPXwjICYLDUAKXD217R

If you have read this far, then I believe you have learnt something new. Do share it with others be leaving some claps, and following. Thanks for reading.

--

--

Qrious Kamal

Name says it. Ever qrious and searching for getting thing done in the easiest possible route. And then document the challenges.