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

90 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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

0
On

Based on source code for asis() it needs string with HTML and it will use it as-is

doc.asis('<script defer src="/js/table_2.js"></script>')

EDIT:

Documentation in point 2. Appending strings "as is" also uses full string with HTML

doc.asis('<!DOCTYPE html>')