czue / celery-progress

Drop in, configurable, dependency-free progress bars for your Django/Celery applications.
MIT License
473 stars 90 forks source link

NoReverseMatch at /status 'celery_progress' is not a registered namespace #108

Closed NicoCaldo closed 1 year ago

NicoCaldo commented 1 year ago

I'm following the documentation but it seems the error won't go away

On my main urls.py I have added as explained in the documentation

re_path(r'^celery-progress/', include('celery_progress.urls', namespace="celery_progress")), # the endpoint is configurable

In my app, where I'm using celery I have a template that should could the JS like

{% block inside-script %}
{% load static %}
<script src="{% static 'celery_progress/celery_progress.js' %}"></script>

<script>
// vanilla JS version
document.addEventListener("DOMContentLoaded", function () {
  var progressUrl = "{% url 'celery_progress:task_status' task_id %}";
  CeleryProgressBar.initProgressBar(progressUrl);
});
</script>
{% endblock inside-script %}

urls.py of the app is

from django.urls import path
from . import views

urlpatterns = [
    path('', views.add_task, name="add_task"),
    path('status', views.tasks_status, name="tasks_status"),
]

But I'm still getting the issue

czue commented 1 year ago

in your main urls.py try adding something like this:

urlpatterns = [
   # all your patterns
   path('celery-progress/', include('celery_progress.urls')),  # add this line
]

and let me know if that works? I'll update the README to be a bit more clear

NicoCaldo commented 1 year ago

Yeah, the issue was I'm pasting it outside the urlpatterns... I'm so dumb

Correct implementation is

from django.urls import re_path, path, include

urlpatterns = [
    re_path(r'^celery-progress/', include('celery_progress.urls', namespace="celery_progress")),  # the endpoint is configurable
]