0👍
✅
After thinking about it, and looking at comments, I decided on the answer of adding a fake parameter and removing it afterwards. Since it will be removed when the form is rendered, the parameter doesn’t much matter. I chose 1
.
So, in my template, I put {% url 'jobs:close' '1' %}
. Then in my javascript, as I call the form in a modal, I use jquery to find the form. It makes it easy just to use the same URL again, so here it is:
var modal = $("#modal");
var closeUrl = '{% url 'jobs:close' '1' %}';
closeUrl = closeUrl.substring(0, closeUrl.length - 2) + event.data.id + /;
modal.find("#close-job").attr('action', closeUrl);
event.data.id
is where I am storing the job ID that I really need.
It isn’t as slick as I was looking for, but it works well.
1👍
Instead of getting ‘foo’ in ajax response, get the reverse url in ajax response and replace the DOM where you need the url.
- Django : How to show form validation errors if form is not valid on base.html?
- ImproperlyConfigured MySQL in Django
- Django Many-To-Many relationships symmetric different types
- Path to static file in Django – 404
- Django + postgres: orderby + distinct + filter() – strange behaviour
Source:stackexchange.com