There are many posts and pages on the use of Django and AJAX, and I have read hundreds in the last day or so am looking for an answer to this question. Short review:
May examples show hardcoded URLs, for example:
$.post("/projects/create/", {"name" : name}, function(data) {...
or some use the URL pattern tag, but without parameters:
$.post("{% url create_project %}", {"name" : name}, function(data) {...
However, I would like to include a Django style parameter in the URL. Here is my url definition:
url(r'ajax/entity_name/(?P<pk>\w+)/$',EntityAjaxView.as_view(),name='entity_name'),
Yes, I use a class based view and it is based on DetailView. This view looks by default for the pk value, which should be specified in the URL, and in a regular template I would use:
{% url entity_name id_number %}
to provide a link. In my code, I want to get the value entered in the input field for the pk value. Here is a snippet of my JavaScript (which doesn't work):
var id_number = $('#id_endowmententity_set-' + rownum + '-id_number').val() $.ajax({ type: "GET", url: '{% url entity_name id_number %}',
So my question is: can I use the URL pattern tag with the value from the input field?
(I know that I could use POST instead of GET and pass id_number in the POST data, but this will not work with DetailView.)
Thanks in advance for your help.