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.

9dafad54b5b4f360b7aae5f482bc1c91?s=128

Tzu-ping Chung

May 19, 2018
Tweet

Transcript

  1. Django After Web 2.0

  2. ࣗݾ঺հ (JP) • ৉ ࢠሯ • νϣϯɾζʔϐϯ • @uranusjr

  3. Me • Call me TP • Follow @uranusjr • https://uranusjr.com

  4. None
  5. None
  6. http://macdown.uranusjr.com

  7. https://docs.pipenv.org

  8. www. .com

  9. None
  10. https://web.archive.org/web/20050801014309/http://www.djangoproject.com:80/

  11. Dynamic Web Pages

  12. None
  13. The Cycle Client Django Request Response

  14. It Works.

  15. Image Credit: Kevin Fox

  16. SPA

  17. Single-Page Application Client Django Request Skeleton User Data Data Render

    Interact
  18. None
  19. None
  20. Frontend Framework Django REST Framework Django Model API

  21. Why Django At All?

  22. Django DB Forms Generic Views Templates URLs Admin Model Forms

  23. Django DB URLs Django REST Framework View Sets Filters Routers

    Serializers API Views
  24. ORM Library REST

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

    • APIStar • Falcon • Flask? Pyramid? • Plain CGI (!)
  26. None
  27. None
  28. Position of Django

  29. Page-Based • Django is a back-end framework • Let it

    do what it is good at • Connect front and back in templates
  30. Django DB Forms Generic Views Templates URLs Admin Model Forms

    Static Frontend Framework
  31. <!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>
  32. Modern Front End • ES6 with modules, TypeScript, etc. •

    SCSS, LESS, Stylus, etc. • NPM and application bundler!
  33. None
  34. {% 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 %}
  35. None
  36. https://owais.lone.pw/blog/webpack-plus-reactjs-and-django/

  37. {% load webpack_loader %} {% render_bundle 'main' 'css' %} {%

    render_bundle 'main' 'js' %}
  38. django-parcel?

  39. View Template Frontend Framework Context ???

  40. <!-- This is a terrible idea. --> <script> var data

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

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

    'main' 'js' %} const contextData = JSON.parse( document.querySelector('#data').textContent )
  43. Take a Step Back

  44. View Template Frontend Framework Produces context Renders
 the UI Also

    renders the UI??
  45. https://stimulusjs.org

  46. Stimulus • By Basecamp (maintainers of Rails) • Interacts with

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

    what’s already there—templates • Mostly server-side integration
  48. Stimulus framework jQuery re-imagined Works for Django too

  49. Django’s Next Steps

  50. DISCLAIMER

  51. Django DB Forms Generic Views Templates URLs Admin Model Forms

  52. Vue (plus tools) Django DB Forms Generic Views Templates URLs

    Admin Model Forms Components View View Model Style States Router DOM
  53. Django DB Forms Generic Views Templates URLs Admin Model Forms

  54. Django DB Forms Generic Views Templates URLs Admin Model Forms

  55. https://channels.readthedocs.io/

  56. https://pybee.org/project/projects/bridges/batavia/

  57. ! "

  58. None
  59. SHAVE THE YAK

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

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