Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django After Web 2.0

Django After Web 2.0

Django, born amist the first web application revolution, is one of the most prototypical “dynamic” web frameworks. Its simplistic request-response cycle, however, does not fit well into the more recent real-time, long-running, client-heavy web applications, and is often sinfully relegated into a REST API provider. The speaker will discuss what Django’s strengths are, and see if there is a way to use Django in a way that fits into the modern web better going forward.

Tzu-ping Chung

May 19, 2018
Tweet

More Decks by Tzu-ping Chung

Other Decks in Programming

Transcript

  1. SPA

  2. ORM • SQLAlchemy • PeeWee • PonyORM • … REST

    • APIStar • Falcon • Flask? Pyramid? • Plain CGI (!)
  3. Page-Based • Django is a back-end framework • Let it

    do what it is good at • Connect front and back in templates
  4. <!DOCTYPE html> <html> <head> <title>This is a bad idea</title> <script

    src="react.js"></script> <script src="react-dom.js"></script> </head> <body> <!-- ... --> </body> </html>
  5. Modern Front End • ES6 with modules, TypeScript, etc. •

    SCSS, LESS, Stylus, etc. • NPM and application bundler!
  6. {% load static compress %} {% compress css %} <link

    rel="stylesheet" type="text/x-scss" href="{% static 'site.scss' %}"> {% endcompress %} {% compress js %} <script type="module" src="{% static 'site.js' %}"></script> {% endcompress %}
  7. <!-- This is a terrible idea. --> <script> var data

    = {{ data_json|safe }} </script> {% render_bundle 'main' 'js' %}
  8. <!-- Better, but still feels wrong. --> <script> var data

    = JSON.parse('{{ data_json|escapejs }}') </script> {% render_bundle 'main' 'js' %}
  9. <script id="contextData" type="application/ json"> {{ data_json|escapejs }} </script> {% render_bundle

    'main' 'js' %} const contextData = JSON.parse( document.querySelector('#data').textContent )
  10. Stimulus • By Basecamp (maintainers of Rails) • Interacts with

    the DOM directly • Works well with PJAX (Turbolinks)
  11. Stimulus • Easy parallel from Rails to Django • Use

    what’s already there—templates • Mostly server-side integration
  12. Vue (plus tools) Django DB Forms Generic Views Templates URLs

    Admin Model Forms Components View View Model Style States Router DOM
  13. ! "

  14. Summary • Pure SPAs don’t really need Django • Django

    is still very good for modern MPA • How can Django fit into the SPA model?