Following up on my previous question, I am facing a challenge in passing a parameter to a view that is only known after the JS executes.
In my URLConf:
url(r'^person/device/program/oneday/(?P<meter_id>\d+)/(?P<day_of_the_week>\w+)/$',
therm_control.Get_One_Day_Of_Current_Thermostat_Schedule.as_view(),
name="one-day-url"),
I have successfully passed this parameter in the URL like so:
http://127.0.0.1:8000/personview/person/device/program/oneday/149778/Monday/
In my template, I include the following:
var one_day_url = "{% url personview:one-day-url meter_id=meter_id day_of_the_week='Monday' %}";
In my JavaScript:
$.ajax({
type: 'GET',
url: one_day_url ,
dataType: "json",
timeout: 30000,
beforeSend: beforeSendCallback,
success: successCallback,
error: errorCallback,
complete: completeCallback
});
While this setup works fine, I need the flexibility to change the day parameter dynamically.
If I modify the JavaScript as follows:
var one_day_url = "{% url personview:one-day-url meter_id=meter_id %}";
and then
$.ajax({
type: 'GET',
url: one_day_url + '/Monday/',
dataType: "json",
timeout: 30000,
beforeSend: beforeSendCallback,
success: successCallback,
error: errorCallback,
complete: completeCallback
});
I encounter a NoReverseMatch error while rendering. This may be due to the URLconf still expecting both parameters.
It seems changing the URL conf breaks the ability to find the view, and keeping it as-is leads to the NoREverseMatch error. Any advice would be highly appreciated.