2

I'm writing the backend for my app using django and django-rest-framework.

The problem I have is that when I set DEBUG=False in my settings, the admin site (along with the browseable rest API) is no longer available, and I got a 500 response.

The console shows no error. Here is a capture of the console log when I try to access /admin/.

enter image description here

The rest API when queried/posted using JSON still works normally.

This is my urlspatterns (I also tried including /admin at the top of the list)

urlpatterns = [
    path("", index, name="index"),
    path("api/", include(router.urls)),
    path("admin/", admin.site.urls),
    path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
]

Since I'm creating my app using react, I'm testing a project structured in a way that all the django apps are contained in the same folder, being the main app: backend. I had to make some minor changes in the apps to accommodate this structure.

For instance, this is an excerpt of how the installed apps:

INSTALLED_APPS = [
    ...
    "rest_framework",
    "backend",
    "backend.projects",
    "backend.tasks",
    "backend.subtasks",
    "backend.comments",
]

And this is a capture of the folder tree.

enter image description here

I think it must be something that changes in app/template discovery when changing from DEBUG=True to False.

Point out that everything else apart from that works correctly: the root of my backend is serving the react app correctly, rest API works correctly as well. And with DEBUG=True all works like a charm.

kiril
  • 4,914
  • 1
  • 30
  • 40
  • 1
    Is any error printed in the console where you run the django app when you visit `/admin`? – Felix Eklöf Nov 11 '22 at 10:37
  • No, only a 500 (I update the question with the console logs) – kiril Nov 11 '22 at 11:42
  • Good question. I haven't had this, so I don't have any specific suggestions, and I don't see how we can help without more details. 1) Have you tried a custom error handler and maybe printing more details? https://stackoverflow.com/questions/67908161/intercepting-a-django-500-error-for-logging-without-creating-serving-a-custom-5? 2) what happens if you removing installed_apps one by one? 3) Can you remove DRF settings, middleware, etc? You are going to have to just start deleting stuff and seeing at least what package causes it to fail. – Andrew Nov 13 '22 at 12:19

0 Answers0