Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

So big news! Async Django.

I have some confusions and will like to clear them by asking some questions.

1. Async Views will require 'NO' need for AJAX?

According to info I have, (don't know what AJAX is but many Django tutorials mention it so it was on my learning wishlist)

Ajax is a set of web development techniques using many web technologies on the client side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.

Isn't this is what asynchronous views in Django will do too?

1A. If Async Django will not completely replace AJAX, Is it worth learning?

2. What does this mean for Channels?

Channels is a project that takes Django and extends its abilities beyond HTTP - to handle WebSockets, chat protocols, IoT protocols, and more. It's built on a Python specification called ASGI.

Can async django replace channels too?

Suggest things related to these topics with reasoning. e.g. Use AJAX with JSON (just an example)

I know that converting Django to async will take time so have this in mind when answering

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm not a python developer but I implemented a couple of web server from the scratch and I think I can help you.

Server Rendering vs Client side Rendering

In web development there are two approaches to deliver content to end users, called Server rendering and client side rendering

Server side rendering (SSR) — the traditional rendering method, basically all of your page’s resources are housed on the server. Then, when the page is requested (commonly from web browsers), the Html, JS and CSS are downloaded. Also frameworks can dynamically can create the html based on backend logic and finally download it. At this point, a lot of frameworks offer wonders for creating apps in no time with "amazing" functionalities.

Technologies : java, c#, python, nodejs, etc

Client side rendering (CSR) — Which is sometimes called "Frontend rendering" is a more recent kind of rendering method, this relies on JS executed on the client side (browser) via a JavaScript framework. So, when page is requested, a minimal , little or empty index.html, css and js were downloaded. Here javascript is responsible to send or receive data and update a minimal section of the page without an entire page refresh.. Finally when user click or trigger some event, javascript will send or receive the data commonly to an api rest (json) using an async call (ajax).

Technologies : react, angular, vue, aurelia, jquery, pure javascript, etc

Django is Server Rendering Framework

As you can see this posts: Simplest CRUD example and Hello World app, you need python (server language) to develop in Django. Django internally creates your html pages and render them to your user.

React(angular, vue, etc) is a Client side Rendering framework

Imagine an api provided by OMS. This api offer us and endpoint to get covid stats by country:

Imagine you are from generation z, and you don't know about java, python, c# and other ancients languages. You need to develop a simple dashboard showing covid stats by first countries who contracted the virus.

Your web will have a visual cool effect : Load home page with empty boxes and one by one, you will show the stats starting for the top ten countries.

To make this effect you will use React to render a home page with empty boxes and you will trigger several requests to the api:

Your home page is still working, user is navigating, scrolling and after some seconds, boxes are filled with stats.

So, we can say that your web performed ASYNCHRONOUS calls allowing for parts of web pages to be loaded dynamically...wait wait This is AJAX :D

Async Views : Python async code with ASGI

One of new challenges for Python web frameworks is adapt to the potential benefits of an asynchronous model.

Django has support for writing asynchronous ("async") views, along with an entirely async-enabled request stack if you are running under ASGI.

The ASGI specification is an iterative but fundamental redesign, that provides an async server/application interface, with support for HTTP, HTTP/2, and WebSockets.

As you can see in the following links, Async Views are not html pages with ajax, since use ASGI, we can say that is an attempt of Django to develop in a async way but IN THE SERVER with python:

Conclusion

Async Views are not html pages with ajax, are just a python code but in async way running in the server.

Your questions

  1. Async Views will require 'NO' need for AJAX?

    • Async Views are code in a python (server) and ajax in a browser. Surely Async View and Ajax are not related.
  2. Isn't this is what asynchronous views in Django will do too?

    • Yes, Async Views is a kind of asynchronous code but in the server, not in the client side like react, angular, etc
  3. If Async Django will not completely replace AJAX, Is it worth learning?

    • It depends of your goals. Currently jobs for web developers (check remote jobs sections of this page -->) are requesting async skills but in client side like react, angular, vue, etc. Java, python and another powerful languages are using its power for backend requirements.
  4. What does this mean for Channels?

    • As your paragraph, channel could be for apis and webs but with server strategy (python).
  5. Can async django replace channels too?

    • I think no. Maybe channels are using or will use async techniques like Async Views.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...