Blog webpage can't find static file

4 directories: pycache, migrations, static, templates

Then I have the following .py files:

init
admin
apps
forms
models
tests
urls
views

Ok, for what we’re trying to find here, we can probably work with just the contents of the static directory within blog.

blog/static contains:

  • 2 directories: admin/ and images/
  • 1 file: test.txt

The admin/ directory contains 127 files and 12 folders
The images/ directory contains 1 file (game_controller.jpg) and 0 folders

Unfortunately, I can’t recreate the behavior you’re describing here with the information provided. Aside from having unnecessary copies of the static files used by the admin, I don’t see anything fundamentally wrong.

What I would recommend as next steps:

  1. Delete all *.pyc files
  2. Delete the extra admin directories
  3. With your known version of runserver stopped, verify that you don’t have a zombie runserver process still executing. (Stop runserver and try to access the server from your browser. If you get a response, then you have a zombie process still running.)
  4. Verify the contents of your manage.py file. (Confirm you didn’t copy this from a different project directory.)
  5. Try to create a new, separate project with just enough code in it to test static file access.
  6. You could also post the complete output from your runserver command, from the command line being issued up to when the first page with static file references being requested.

I seem to have fixed the issue.

I did so by adding the following to settings.py:

MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

And updating personal_blog/urls.py:

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('blog.urls')),  # Include your blog URLs
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Hopefully this helps someone else. It must have been a step I missed at some stage.

These settings have nothing to do with static files. Making these specific changes would not have fixed the issue you described - it would have been coincidental with some other change or correction being made.
(I’m only pointing this out because this - by itself - is highly unlikely to resolve anyone else’s static file issue.)