Valentino Gagliardi

Decoupled Django

Understand and Build Decoupled Django Architectures for JavaScript Front-ends

1st ed.
Valentino Gagliardi
Colle di Val D’Elsa, Italy
ISBN 978-1-4842-7143-8e-ISBN 978-1-4842-7144-5
© Valentino Gagliardi 2021
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.
The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress Media, LLC part of Springer Nature.

The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.

To my grandfather, Valentino. I will always miss you.


If you’re reading this, I’m glad! It means you are interested in Django, one of the most powerful and flexible web frameworks out there.

When I discovered Django years ago, I realized I could make perfectly working prototypes faster than with any other web framework; prototypes that later would become robust, rock-solid web applications.

These days, with JavaScript all the rage, the temptation to jump on the JavaScript-full-stack bandwagon is strong, and sometimes this tendency makes beginners think that everything must be built with JavaScript. It shouldn’t. Even if I work primarily with JavaScript, Django is still my safe harbor for building stuff quickly.

At the same time, used with cognition, modern frontend libraries like Vue.js and React pair well with Django, which can work completely decoupled from the frontend. This book is an attempt to cover a part of the vast spectrum of decoupled architectures with Django and JavaScript, with an eye on the last developments in the asynchronous Django land, and on the integration between Django and GraphQL. Here’s a breakdown of what you can expect from each chapter.
  • In Chapters 1, 2, and 3, we introduce the terminology, what makes a decoupled architecture, how modern JavaScript is supposed to work in Django, and how the Django REST framework can help you build REST APIs.

  • In Chapter 4, we discuss the advantages and drawbacks of a decoupled architecture.

  • In Chapters 5 and 6, we begin to build a Django project with the Django REST framework and Vue.js to show how Vue can work from within Django templates.

  • In Chapter 7, we discuss security for REST APIs, and deployment of our Django/Vue.js project.

  • In Chapter 8, we move to React and Next.js to show how such a framework can be paired with Django. We cover Next.js basics and data fetching.

  • Chapter 9 covers testing, both for the REST API and for the JavaScript frontend.

  • Chapter 10 covers authentication for decoupled setups and shows you how to use session-based authentication for single-page apps with the help of NGINX.

  • Finally, in Chapters 11 and 12, we cover GraphQL in Django, with a look at running Django asynchronously.

All the system commands presented in this book assume that the reader is using a Linux or MacOS system. As for the prerequisites, a basic knowledge of TypeScript and modern frontend libraries is expected.

Have fun!


This book is the product of my love for Django and its community.

I’d also like to express my gratitude to the Italian Python community in particular, one of the most welcoming out there!

Table of Contents
Index 231
About the Author
Valentino Gagliardi

is a freelance consultant with many years of experience in the IT industry. He spent the last several years as a frontend consultant, providing advice and help, coaching, and training on JavaScript and React. He worked as an instructor for many training agencies around the country, running in-person workshops and creating learning paths for aspiring developers. Author of The Little JavaScript Book, he loves to share his knowledge on his blog, with his tutorials reaching over 100k monthly visits. An avid Django user, he is active in the Python community as a speaker and as a coach for Django Girls.

About the Technical Reviewer
Marcin Gębala

is a software engineer specializing in building web apps with Python and Django, which he has been doing professionally since 2014. He works as a staff engineer, leading the backend team, which develops the GraphQL API. He has spoken at several tech conferences, including GraphQL Summit and PyCon Korea, and his main topics of interest are open-source, Python, and GraphQL. In his free time, he is a runner, musician, and traveler. He is based in Wrocław, Poland.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.