Python Forum
Django - Passing data from view for use client side with JavaScript in a template
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Django - Passing data from view for use client side with JavaScript in a template
Hello everyone,

I am developing a text-based RPG game in Django for learning purposes and I am wondering what the best way would be to run an event (such as a fight between two characters) server side, and instead of simply passing the result back to the client via a template, such as who won, I want to re-run this 'fight' but in a slower speed using JavaScript. This would show each characters 'turn' and the damage they dealt, although this would be processed instantly on the server.

The methods I thought about using were as follows:
  • Pass the combat log/fight through to the template via a context variable using some dictionary or JSON and access the template variable via JavaScript (if this is possible to even do, is it best avoided?)
  • Send this data to an API which the JavaScript code in the template will fetch and modify to show at a reduced speed

Does anyone have any better solutions? I don't think I should be posting the outcome of each fight using an API just to transfer this data to client side for use with Javascript, it's a waste of storage if this is the only use. I am wanted to do the first option - accessing it via a template variable using JavaScript which would be a dictionary


Possibly Related Threads…
Thread Author Replies Views Last Post
  DJANGO Looping Through Context Variable with specific data Taz 0 460 Feb-18-2021, 03:52 PM
Last Post: Taz
  how to pass javascript variables to url_for function in a flask template experimental 5 2,920 Oct-29-2020, 03:29 AM
Last Post: universe
  Django serving wrong template at the wrong address with malformed (redactor a Drone4four 2 831 Aug-17-2020, 01:09 PM
Last Post: Drone4four
  Sending data from a websocket client to another server lemon 1 959 May-25-2020, 02:26 PM
Last Post: lemon
  Why use HTML in Django Template ift38375 2 1,238 Dec-09-2019, 02:28 AM
Last Post: snippsat
  Unable to access javaScript generated data with selenium and headless FireFox. pjn4 0 1,197 Aug-04-2019, 11:10 AM
Last Post: pjn4
  how retrieve database save multiple data in web Django 2.1 taomihiranga 0 1,376 Jul-30-2019, 04:58 PM
Last Post: taomihiranga
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 1,404 Jun-30-2019, 12:21 AM
Last Post: scidam
  Django - Retrieve form data justantest 0 1,625 May-23-2019, 11:47 AM
Last Post: justantest
  Passing a query value from a Bottle html template to a route with an encoding nikos 0 1,537 Sep-30-2018, 03:29 AM
Last Post: nikos

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020