Dynamically create – Code-Apprentice May 17 '21 at 05:42

  • This idea is bad design. You simply make your site vulnerable by doing this. All one needs is to get the url of a malicious script in `movement.script_source` and your website is hacked. As @Code-Apprentice say perhaps the script can be the same but work with different data, which you can give to it using data-attributes on the HTML, and various other much more _safer_ ways. – Abdul Aziz Barkat May 17 '21 at 06:44
  • @Code-Apprentice I am sure it is a bad design as I am a novice coder... When I use this code to access an external script file, it works as expected: However, each instance of the mixer control on each card needs its own script file, that's why I need the src of the script file to be dynamically generated. – Michael May 17 '21 at 06:57
  • From what I have read in other posts, it seems I am going about it in completely the wrong way. I think the solution will be to write what I need in a django View first, then inject that into the HTML – Michael May 17 '21 at 11:28
  • @AbdulAzizBarkat I agree that this seems like a suspicious way to do things. Whether or not a malicious actor can do anything depends on how the `movement.script_source` is set. If there is no way for the user to set it, then there is less risk. – Code-Apprentice May 17 '21 at 17:23
  • @Michael Why do you think each mixer control instance needs its own script file? Does every mixer control have completely different behavior? If so, what are the differences? Can those differences be encapsulated in data that can be processed all by the same script? – Code-Apprentice May 17 '21 at 17:23
  • @Code-Apprentice Each mixer instance needs it's own configuration script as that references different mp3 files, for example, the first movement of a sonata for 3 flutes would consist of 3 mp3 files, one for each flute, thus creating an individual channel for each flute on the mixer. The student can than then mute any of the lines and play along. The second movement would have its own configuration and mp3 files accordingly – Michael May 18 '21 at 05:46
  • 1
    @Michael doesn't that just mean you can make a common function / script that can take as input an array of mp3 files? Always remember one should make their code as dynamic and reusable as possible and try not to repeat themselves. – Abdul Aziz Barkat May 18 '21 at 07:40
  • @Michael I agree with Abdul Aziz Barkat. You should be able to do this with one script file for all mixers. You just need to pass different data for each mixer to the script. This can be done several ways: 1. Make a REST endpoint to get the MP3 files/data 2. Embed the MP3 data into the page directly as JSON. – Code-Apprentice May 18 '21 at 14:23
  • @Code-Apprentice and Abdul Thank you. I will explore these suggestions – Michael May 18 '21 at 17:24
  • 0 Answers0