Static files not loading | fixed as per previous blogs and now everything not working

I had troubles with static files not loading and followed the previous blog posts here.
After completing all steps, my entire app is not working any more (previously, only the static file main.js was not working when rendered/in production/on the URL provided by render).

Now, however, nothing is working anymore and I have a wave of ServerError (500). This ServerError(500) did not exist BEFORE I completed the steps below. So, the ServerErrors(500) can only be the result of the steps below. Any of the steps below incorrect? Anything I should have done in different order? Typos?

I also added bootswatch as CDN to all my templates (even thought bootswatch seems to have been loaded properly). Just to make sure that bootswatch is not creating the issue.

I do have error message on “HEAD”, so presumably this still relates to loading of static files.
In my index.html I do load the STATIC js/app.js and this is likewise showing me error. So, presumably, because my script with STATIC js/apps.js is not working (indication that static files are not loading properly), I end up with all these 500 errors?

Step 1:

I did not have STORAGES in my settings.py (so, I added this):

STORAGES = {
“staticfiles”: {
“BACKEND”: “whitenoise.storage.CompressedManifestStaticFilesStorage”,
},}

Reason why: django 4.2 does not support STATICFILES_STORAGE = ‘whitenoise.storage.CompressedManifestStaticFilesStorage’

Is this thought correct?

Step 2:

This STORAGES = {} is used in the if not DEBUG condition.

STATIC_URL = ‘/static/’

if not DEBUG:

STATIC_ROOT = os.path.join(BASE_DIR, ‘staticfiles’)

STORAGES = {
“staticfiles”: {
“BACKEND”: “whitenoise.storage.CompressedManifestStaticFilesStorage”,
},}

Is the thought correct to use the STORAGES = {} here instead of using STATICFILES_STORAGE as the second if-not condition here?

Step 3:

I added ‘whitenouse.middleware.WhiteNoiseMiddleWare’ into MIDDLEWARE as per post Trouble Serving Static Files on Django App Deployed with Render - #3 by WebsiteCentral.co

MIDDLEWARE = [

‘django.middleware.security.SecurityMiddleware’,

‘whitenoise.middleware.WhiteNoiseMiddleware’,

‘django.contrib.sessions.middleware.SessionMiddleware’,

Step 4:

The post says, Quote: make sure django.contrib.staticfiles.middleware.StaticFilesMiddleware’,

in your middleware is not commented…

Question: what dos “commented” mean? Commented out? Use of #?

How could I make the above “commented”, i.e. what would I need to do to make the above “commented” assuming it is NOT commented?

Step 5:

As per same Post from above that ends on /16037/3

I also did go to urls.py and added

if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Are the two urlpatterns += indendented below the the if-statement? Presumably, yes.

This if statement sits in the urls.yp of django project, right?

Step 6:

I included whitenoise in my requirements.txt file as project dependency

Whitenoise

Step 7:

All and everything except staticfiles worked when I deployed. After completing the steps above of including static files via something that is called WhiteNoise I do have numerous 500 errors. So, something that has worked before now creates numerous 500 errors. All of these 500 errors seem to be related to staticfiles not loading/rendering.

So, now nothing works any longer. Neither staticfiles rendering/loading nor does anything else of the code run any more.

127.0.0.1 - - [24/Apr/2024:09:35:14 +0000] “GET / HTTP/1.1” 500 145 “-” “Go-http-client/2.0”

127.0.0.1 - - [24/Apr/2024:09:35:27 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

127.0.0.1 - - [24/Apr/2024:09:35:29 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

127.0.0.1 - - [24/Apr/2024:09:35:34 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

127.0.0.1 - - [24/Apr/2024:09:35:35 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

127.0.0.1 - - [24/Apr/2024:09:35:36 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

[2024-04-24 09:36:12 +0000] [75] [INFO] Handling signal: term

[2024-04-24 09:36:12 +0000] [76] [INFO] Worker exiting (pid: 76)

[2024-04-24 09:36:13 +0000] [75] [INFO] Shutting down: Master

127.0.0.1 - - [24/Apr/2024:09:36:30 +0000] “GET / HTTP/1.1” 500 145 “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36”

This is how I tried to resolve the issue but I continue to have a ServerError(500) on an html tag that does not even exist in my template/index.html

Step 1:
Ensured that a version number is included in requirements.txt file. In my case whitenoise==5.3.0
My django version used is 5.0.3 | Presumably, these two versions, means: the version of whitnoise and version of django, are compatiable

Step 2:
Console shows this:

Server Error (500)

Server Error (500)

What I DO HAVE in my index.html, i.e. the template for which the console shows the error above, is:

{% load static %}

<html lang="en">

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootswatch@5.1.3/dist/morph/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="{% static 'css/styles.css' %}">
        <title>My thoughts and todos</title>
    </head>

and, for the ServerError(500) at the bottom

  <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>

Problem/concern: The console of the ServerError(500) shows

Server Error (500)

In my entire index.html I do not have a heading tag of h1. I do not have any heading tag of any nature, i.e. neither h1 nor any other heading tag between h1 and h6.

Question: How can my console refer to a ServerError(500) in a heading tag if I do not even have a heading tag in the template (concise: index.html) where this ServerError(500) is shown? That is strange…Reference of error to something that does not exist in the template.

Step 3:
Since there was a ServerError(500) in the of the index.html, I removed the title altogether. So, now there is no longer a tag in the index.html where the console reported ServerError(500) for the tag

Step 4:
I cleared cache for the page that shows ServerError(500). I refreshed the dashboard on renderseveral times after trying to deploy again

Step 5:
After having deleted the tag in my index.html (as it presumably created an issue),
Step 6:
After having removed the tag in my index.html I “reduced” the 500 error messages down to this
127.0.0.1 - - [24/Apr/2024:10:22:46 +0000] “HEAD / HTTP/1.1” 500 145 “-” “Go-http-client/1.1”
==> Your service is live :tada:
127.0.0.1 - - [24/Apr/2024:10:22:54 +0000] “GET / HTTP/1.1” 500 145 “-” “Go-http-client/2.0”
My application logs shows the same.

So, I did have removed the tag in my index.html and still do not have any heading tags of any conceivable nature but my console is saying:

Server Error (500) and this is wrapped into a title-tag
Another Server Error (500) wrapped into a h1 tag

Step 7:
I can see the green button named “Live” but I can not click that button. Is this an indication for something?

Step 8:
Tried to run my https://todo-daeo.onrender.com/ on a different browser. ServerError(500) continues to be displayed.

Hi,

As this is an application-level issue, we are limited in our ability to assist you here.

Adding more verbose logging for troubleshooting could be helpful.

You mentioned this used to work, I’d suggest try rolling back to the last working commit. Give that a try and let me know how it goes.

Best,

Matt.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.