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
#1
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

Thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  view option in Django Sowmya 1 258 Mar-29-2024, 12:41 PM
Last Post: SULMAN
  Python django view error ZeeKolachi 1 317 Mar-18-2024, 03:14 PM
Last Post: Sowmya
  Django: View is unable to find attributes of database model pythonpaul32 0 509 Dec-07-2023, 06:38 PM
Last Post: pythonpaul32
  Initializing a Serializer in init and passing data later wolfman5874 1 1,418 Nov-01-2022, 10:51 PM
Last Post: wolfman5874
  Save JSON data to sqlite database on Django Quin 0 2,864 Mar-26-2022, 06:22 PM
Last Post: Quin
  django - reset password template rwahdan 2 1,983 Dec-26-2021, 09:09 PM
Last Post: Jeff900
  DJANGO Looping Through Context Variable with specific data Taz 0 1,812 Feb-18-2021, 03:52 PM
Last Post: Taz
  how to pass javascript variables to url_for function in a flask template experimental 5 6,379 Oct-29-2020, 03:29 AM
Last Post: universe
  Django serving wrong template at the wrong address with malformed urls.py (redactor a Drone4four 2 2,567 Aug-17-2020, 01:09 PM
Last Post: Drone4four
  Sending data from a websocket client to another server lemon 1 3,575 May-25-2020, 02:26 PM
Last Post: lemon

Forum Jump:

User Panel Messages

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