How to pass a Jinja variable inside a Svelte component (Django/Flask)

Viewed 383

I have a Flask app, and I need to pass a variable called var to Svelte component App.Svelte

In a HTML, I would do {{ var }} but this confuses Svelte as it uses { } for its delimiters, and says var is not defined. In Vue, we can define different delimiters for Jinja (such as []) to solve this problem, but in Svelte I could not find how to do it.

How can I pass a variable to Svelte?

1 Answers

I do it like this:

    <script>
        var variable = "{{your_django_variable}}";
    </script>

Just make sure you're loading it before loading Svelte

Related