Server Error (500) when accessing Django app upon successful deployment

I’m having a hard time trying to deploy a Django app on Render. The app is currently deployed on Heroku on the hobby tier.

I first created a Blueprint that linked to my GitHub repo and a PostgreSQL database for the app. The Blueprint’s status says “sync succeeded” and database’s status “available.”

I then followed the guide here and tried to migrate the app, but it kept failing for whatever the reasons that I no longer recall. I next followed the guide here (only the “Update Your App for Render” part; I don’t have Poetry and just tried to deploy the existing app) and tried to deploy the app afresh.

After repeated attempts and modifications (including changing the django version from 4.1.3 to 3.2.16 when prompted by the "no django version found to match 4.1.3 error message), the status of the app finally says “Deploy succeeded” on the Dashboard of my account. But when I tried to access the app at the URL given by Render, it displays only “Server Error (500),” as shown in the 1st image in the attached file. I can see that the page loads the favicon.ico, indicative that it has access to RENDER_EXTERNAL_URL/static/, but somewhat can’t access other static resources or the index.html.

The Logs on my Dashboard indicates a “GET /login?next=/ HTTP/1.1” 500 145," as shown in the 2nd image in the attached file. I don’t understand the “145” that follows the “500.”

My settings.py file has relevant settings as shown in the remaining images in the attached file. Please kindly advise just where does it go wrong.

Hi there,

Thanks for reaching out.

You may need to enable debugging temporarily to see what is raising the 500, as the error is coming from your app. The /admin path seems to respond with a login page without a 500.

145 is the size of the response, e.g.

curl -so /dev/null https://jtc-bridgeapp.onrender.com/login?next=/ -w '%{size_download}'

Kind regards

Alan

Hi, Alan. Thank you for assisting and the suggestions. Following your advice I changed DEBUG = 'RENDER' not in os.environ to DEBUG = True (settings.py line 31) and if not DEBUG: to if 'RENDER' in os.environ: (line 128) (see screenshots attached below). And the app deploys and works normally now.

So the only determinant change is whether DEBUG is turned on; however, it obviously is not desirable to have it on on deployment. Is there any get-around to this? What should I do?

Appreciate your insights.

I’m, I’m not a Python expert. I suggested changing DEBUG to True to see if you got more verbose logging on your original issue. If that fixed the problem, then it feels that DEBUG = 'RENDER' not in os.environ may not have worked as you expected.

I agree, debug mode is not desirable for production, so have you tried changing DEBUG to False rather than a conditional? If that still works, then it appears DEBUG = 'RENDER' not in os.environ was the issue. Unless you’ve also made other changes.

Alan

Hi, Alan. Thanks again for your time. I’ve done further investigation into possible solutions; however, nothing other than setting DEBUG = True worked. I first tried as you suggested to set DEBUG = False and the app returned to giving Server Error (500),

It appears the env variable RENDER is being passed in wherever it’s invoked–so 'RENDER' not in os.environ evaluates to False that causes the issue here.

I also tried to hardcode the host names into the ALLOWED_HOST list (e.g., ['localhost', 'jtc-bridgeapp.onrender.com']) to ensure the hosts are known to the app, because ALLOWED_HOST list needs to be specified when DEBUG = False. Still the app deployed normally only to produce Server Error (500).

I’m exhausted at this point and would appreciate any helping hands.

This isn’t a Render issue, but a code issue. Debugging code issues is beyond the scope of our support, as every app is different.

However, in this case, to confirm that this definitely isn’t a Render issue, I dug a little deeper.

As I’ve said before, I’m not a Python expert, but searching Google for “django 500 debug false”, brings up this Stackoverflow article as the top result. Which includes some suggestions, including adding additional logging. The linked example writes logs to a file, but if you’re using a free plan, you wouldn’t have Shell access to see that file. So you can refer to the Django docs to make those logs output to the console (example). With that in place, you should be able to see what the underlying error is when running the app with DEBUG=False.

As the repo is public, I spun up my own copy with the logging config added. The error was shown in the logs:

ValueError: Missing staticfiles manifest entry for '/images/bryan-profile.jpg'

Again, not being familiar with Python/Django, and Google being our friend, the top result for a “missing staticfiles manifest entry” search was another Stackoverflow article. With a suggested solution being incorrect leading slashes / on static declarations.

That’s your issue.

Alan

It seems our support system community integration doesn’t like inline links :person_facepalming: Here are the links I mentioned above:

Alan

Thank you very much, Alan, for the time you spent in assisting me in this matter. The suggestion links helped me find the issue, and it was indeed misplaced '/'s in the static resources links in my template files. My inexperience in looking for a solution had also compounded the problem, it seemed.

So Cory’s answer to the Stack Overflow question here was dead on the issue I encountered. I’m truly grateful for your help.