r/WatchPeopleCode • • Feb 04 '20

Create HTML pages with Python Using the Dominate Module

http://Www.youtube.com/watch?v=sJA-n-_nKAg
34 Upvotes

7 comments sorted by

2

u/Basicallysteve Feb 04 '20

That’s pretty cool! What advantages might this have over handling HTML from django or flask?

3

u/lonelymonad Feb 05 '20

Django does many other things compared to Dominate, such as URL routing, handing authentication, providing an ORM for easier and pythonic database usage. Whereas Dominate is (from what I can tell) is an HTML generator, not a full-blown web framework. If we are specifically comparing the HTML rendering between Django and Dominate, Django uses jinja2 templating engine. You can find more information about it in its documentation, but put simply, you write it as it you write HTML, with some python logic sprinkled in it via jinja's special markup. Jinja converts those markups to actual HTML while rendering.

In other words:

  • Jinja2 (hence Django) makes you write HTML with additional jinja syntax for logic.

  • Dominate makes you write pure Python to generate HTML.

1

u/Basicallysteve Feb 05 '20

Thanks for the clarification. I guess the heart of my question is really to understand where dominate would be useful? I haven’t had to generate HTML much outside of web frameworks, so I assumed it would have a use-case within those.

1

u/__---__---___ Feb 05 '20

There are also many cases where you don't need a framework and you only need to generate static HTML files.

For example, I use this to create e-mails for various purposes.

1

u/Basicallysteve Feb 05 '20

Huh, I forgot emails can/do use HTML. Thanks for the heads up

1

u/Wilfred-kun Feb 04 '20

Seems like a fun little project! Can you share the source code for this (link in the video description is broken)?

1

u/__---__---___ Feb 05 '20

Yeah no problem. Thanks for pointing out the broken link.

I've fixed it now, but here it is for ease:

https://codeyogi.co.uk/2020/02/04/create-html-pages-with-python-using-the-dominate-module/