Skip to content

script type=module #358

Discussion options

You must be logged in to vote

I was hoping to be able to set it on a per component basis, I think the above code would add type=module to all script tags would it not?

I was able to achieve what I needed without making any code changes after spending some time looking at the Django Media class

It turns out since 4.1 the js file path can actually be an object that implements an html() method (https://docs.djangoproject.com/en/4.1/topics/forms/media/#paths-as-objects)

That means you're able to directly specify how the script tag should look by doing something like this

class My_component(component.Component):
    template_name = "my_component/template.html"

    def get_context_data(self):
        return {
           # …

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by JuroOravec
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants