Django view doesn't work at all after setting debug=False

I am stuck in this problem for a whole day and the irrationality of this problem is wretching.

# urls.py
path('check_progress/<str:task_id>/', views_data.check_progress, name='check_progress'),
#views.py
def check_progress(request, task_id):
    logger.info(f"Entered check_progress with task_id: {task_id}")

    try: 
      task = AsyncResult(task_id)
      data = {'state': task.state, 'percent': 0}

      if task.state == 'PROGRESS':
        task_info = task.info or {} # from self.update_state(state='PROGRESS', meta=TASK_INFO)
        data['percent'] = task_info.get('percent', 0)
    
      elif task.state == 'SUCCESS':
        data['percent'] = 100

      return JsonResponse(data)
  
    except Exception as e:
      logger.error(f"check_progress() failed. {e}")

When DEBUG = True

2024-01-24 01:24:42 [2024-01-23 17:24:42 +0000] [7] [DEBUG] GET /check_progress/abcg/
2024-01-24 01:24:42 2024-01-23 17:24:42,116:INFO - Entered check_progress with task_id: abcg

When DEBUG = False

[DEBUG] GET /check_progress/
2024-01-24 01:25:23 Internal Server Error: /check_progress/
2024-01-24 01:25:23 2024-01-23 17:25:23,980:ERROR - Internal Server Error: /check_progress/
2024-01-24 01:25:30 [2024-01-23 17:25:30 +0000] [7] [DEBUG] GET /check_progress/erergg
2024-01-24 01:25:30 Internal Server Error: /check_progress/erergg
2024-01-24 01:25:30 2024-01-23 17:25:30,964:ERROR - Internal Server Error: /check_progress/erergg

The debug settings is the only cause of problem. The weird thing is that this is the only endpoint with issue. Other endpoints dont have the same problem.

I cant even execute the first line of the view function. The view itself is broken.

You’re not passing the parameter in the second example. The get shows that you’re attempting to access a url named /check_progress, which doesn’t match anything you’re showing in your urls.py.

I copied the wrong log. But even after passing a parameter, it doesnt work.

Your GET still doesn’t match the URL. The url is defined with a trailing slash, but your GET doesn’t show that slash as being present.

With debug = True, there should be a complete stacktrace printed in your server’s log. (How are you running your application? Which server are you using?)

Also, your title isn’t consistent with the post - when is the error occurring? When DEBUG = True or DEBUG = False? Your title says that the view isn’t working when DEBUG = False, but you’ve labeled your logs such that the error occurs when DEBUG = True.

It’s the trailing slash. Apparently, when debug is set to True, the trailing slash automatically appends. When debug is set to False, somehow it doesn’t.

Note the trailing slash is present here in the request. Django isn’t appending it, unless you see the previous request being a redirect.

Also see Settings | Django documentation | Django