0
<script type="text/javascript">
    var a = "{{Django_Variable}}"
</script>

I get this idea.

But what if these Django Template variables contain sensitive information? I have written a Javascript application that needs to receive data from Django, but my current implementation shamelessly displays all the details in developer mode.

<script>
    $(function() {
        MyApp.init(
            userid: 46,
            hasPermission: False,
            secretData: "Not anymore",
            ...
        );
    });
</script>

The data I'm trying to pass in are not as sensitive as credit card or password information, but sensitive enough that I need to hide it. I have considered firing AJAX GET after the page loads, but that just adds extra overhead.

How do I pass in Django Template variables to my Javascript without showing it in HTML?

Thank you.

1 Answer 1

1

There are no real differences when it comes to this whether it be django or any other framework . The problem inherently has to do with the fact that javascript is client side technology. However yes ajax request is one possible . Others can be minifying/encrypting etc ... Anything that you would use for any other framework. I would say you should read these answers to get a better picture:

Secure data in JavaScript

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.