简体   繁体   中英

Best practice working with python variables in javascript django

I am currently accessing my python data in JavaScript like this:

<script>
    var x = {{ x | safe}};
    var l = {{ l | safe }};
    var sf ={{ sf | safe }};
</script>

this works but does not seem like the most ideal way to transfer data. What is the best practice for accessing and saving data between python and javascript using django?

What I am trying to do is send data from the view, manipulate it using the ui in javascript/vue.js and then save the calculated data.

There are a few different ways to accomplish what you're asking about. I would recommend using Django Rest Framework to create a RESTful API as the "best practice" for interacting with a JS client-side app.

The most helpful way forward might be to start with a tutorial and then return as more specific questions come up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM