Web development in 2021 is so dominated by JavaScript and its many frontend frameworks, it’s sometimes easy to forget that the traditional server-side web application architecture is not only alive and well — but thriving. 55.3% of Django developers who took the annual StackOverflow survey said they will continue to use it; and 49.3% said the same of Ruby on Rails. Django and Ruby on Rails — two of the leading backend web development frameworks and both open source — have been on the scene since the mid-2000s. They’re no longer the trendy young bucks in web development, but they are still the seventh and 11th most-loved web frameworks respectively.

In a column earlier this year, I discussed how Basecamp — the company that created Ruby on Rails — is adapting to frontend trends with a newly released framework called Hotwire. One of the goals of Hotwire is to reduce the amount of JavaScript code being used, by “sending HTML instead of JSON over the wire.” It’s both a challenge to the JavaScript reliance of leading frontend frameworks like React and Next.js, but also a way for Ruby on Rails to stay relevant.

To find out the Django perspective on our current JavaScript-heavy web landscape, I reached out to one of its co-creators — Simon Willison. Nowadays Willison is focused on his latest project, Datasette, an open source tool he created for exploring and publishing data. But he’s best known for co-creating Django in 2003, as a Python framework to help developers build complex, database-driven websites. At the time Willison and his co-creator Adrian Holovaty were working for a small US newspaper, so the idea was to help the paper’s writers and editors easily put content into a database that would then get published to the website.

Over the past fifteen or so years, Django has become an integral part of a number of massive-scale internet products, such as Instagram, Pinterest and Spotify. As an Instagram engineer noted in September 2019, “Instagram Server is a Python monolith with several million lines of code and a few thousand Django endpoints.”

What’s less known is that Django is sometimes used alongside the likes of React and Vue, two of the leading frontend frameworks of today. This shouldn’t be a surprise — Instagram clearly uses both Django and React, since the latter is a project run by its parent company Facebook. But judging by a recent Twitter comment by Willison, it’s a common misconception that Django can’t work with JavaScript frontend frameworks.

“The technically correct answer,” Willison told me when I asked him about this, “is that a backend framework like Django works with any frontend framework, because of separation of concerns: if a web framework can respond to HTTP requests with JSON and HTML, it can be used with anything.”

However, he noted there are aspects of the Django/JS framework relationship that confuse people, “especially newer developers.”

“Things like JWT [JSON Web Token] for authentication are a hot topic — core members of the Django project think JWT has a flawed design and have argued against shipping support for it in Django core, leaving it to third-party packages. But lots of developers want to use JWT and have a hard time figuring out how to do it.”

The default solution, he said, is to use the Django REST framework, a toolkit for building Web APIs. This toolkit includes support for JWT. An alternative, which he himself often uses, is to write standard Django views that return JSON.

The case for pairing the two frameworks would be to use React to handle the user interface, fetching data from the Django backend as necessary. For example, this tutorial shows how to build a to-do application, with React making HTTP requests to the Django REST API in order to fetch and set data.

#development #op-ed #profile #django’s #react #django’s place in a web development world ruled by react

Django’s Place in a Web Development World Ruled by React
1.35 GEEK