简体   繁体   中英

Reverse for 'task_status' with arguments '('',)' not found. 1 pattern(s) tried: ['celery-progress/(?P<task_id>[\\w-]+)/$']

document.addEventListener("DOMContentLoaded", function () {
  try {
      var progressUrl = "{% url 'celery_progress:task_status' task_id %}";
      CeleryProgressBar.initProgressBar(progressUrl);
  }
  catch(err) {
  }

As you can see from the above code in my index.html I'm trying to catch the exception in my title using a try catch statement in javascript. However, as the error is occuring in python...how do you modify the above code to say "if no error do this, if not":

{{index | safe}}

(Or just catch the exception and do nothing)

Assuming your using a templating language, you could avoid any errors by just checking if the task_id exists, since the error you are trying to catch is from an empty value.

This is what I did.

 {% if task_id %} <script> document.addEventListener("DOMContentLoaded", function() { var progressUrl = "{% url 'celery_progress:task_status' task_id %}"; CeleryProgressBar.initProgressBar(progressUrl); }); </script> {% endif %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM