[Answer]-Is there any established way to get kwargs for a page view in JS?

1👍

AFAIK there is no standard approach. You can:

  • put JS into template and render view variable
  • pass variable in JS globals, setting it’s value in template text
  • parse window.location
    …etc.

I personally prefer the second way, e.g. put this code in template and then use _reset_pw_code global in javascript file:

<script> var _reset_pw_code = "{{ reset_code|escapejs }}" </script>
👤Marat

0👍

Recently JavaScript added a new API to do this it is currently still experimental.

const pattern = new URLPattern('reset_pwd/:code/', 'https://example.com');
console.log(pattern.exec('https://example.com/reset_pwd/thECode/').pathname.groups); // { code: 'thECode' }

https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API

Leave a comment