Search code examples
pythonyattag

How can I add the "defer" attribute in a line of code in yattag?


I'm trying to write this html line of code:

<script defer src="/js/table_2.js"></script>

in yattag format as follows:

doc.asis("script", defer="defer",src="/js/table_2.js")

but I get an error in the defer attribute, does somebody know how to include this attribute in a yattag line of code?


Solution

  • Attributes that don't have a value can be passed as simple strings:

    with tag("script", "defer", src="js/table_2.js"):
        pass
    

    There's an example like this at the end of the paragraph about the tag method: https://www.yattag.org/#the-tag-method