Asynchronous Django, Ajax, Jquery Information

前端 未结 2 763
半阙折子戏
半阙折子戏 2021-01-12 02:12

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 AJA

2条回答
  •  余生分开走
    2021-01-12 02:52

    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:

    • https://oms.api/covid/stats/country/{country-id}

    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:

    • (china) https://oms.api/covid/stats/country/ch
    • (usa) https://oms.api/covid/stats/country/eu
    • (italia) https://oms.api/covid/stats/country/it

    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:

    • https://docs.djangoproject.com/en/3.1/topics/async/
    • https://www.encode.io/articles/hello-asgi

    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.

提交回复
热议问题