What to do if Django can't load an image from a static folder

The bottom line is that it just rebooted. It may not be enough to post it, but I thought that I might be addicted to this kind of place unexpectedly.

Status

In django, I made an app called posts in a project called myblogapp. At this time, I added a new static file and tried to load the image.

myblogapp  └posts    ├ templates    | └ posts    |   └ index.html    |    ├ static        ⏋ | └ posts | ← Make here    |  └ home.html   ⏌    |    | (Others such as views.py are omitted)

In ʻindex.html`

{% load static %}
<img src="{% static 'posts/home.jpg' %}" alt="home image">

It was when I tried to display the image by writing.

The problem that occurred

The image is not displayed even though it is specified correctly Just a mark indicating that there is no image and the word "home image" are displayed. The image did not load correctly.

Looking at the display on the shell running django

[(Date and time)] "GET /static/posts/home.jpg HTTP/1.1" 404 1668

Is displayed and 404 is returned. You can see that the existence of the file is not recognized.

solution

I stopped django's server once, and then ran python manage.py runserver again and it loaded normally. (Correctly, stop the server once and run python manage.py findstatic . Make sure the static directory is recognized properly I ran python manage.py runserver. )

Any program If it doesn't work, you should restart it for the time being. I realized it again ...

Recommended Posts

What to do if Django can't load an image from a static folder
What to do if you get an error when trying to load mnist
What to do if you can't pipenv shell
[Django] What to do if an Integrity Error occurs when registering data from the management site to the database
What to do if you can't pip install mysqlclient
What to do if a UnicodeDecodeError occurs in pip
What to do if you get an "unknown service" error from your gRPC server
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if pip gives a DistributionError in Homebrew
What to do if you can't sort files with subscripts
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you can't log in as root
What to do if you can't use WiFi on Linux
What to do if yum breaks
Convert a string to an image
What to do if you can't install pyaudio with pip #Python
What to do if you get a minus zero in Python
Try to extract a character string from an image with Python3
What to do if you get a UnicodeDecodeError with pip install
What to do if you can't build your project with Maven
What to do if you can't use the trash in Lubuntu 18.04.
Django: What to do if TemplateDoesNotExist at / admin / after setting templates
[Django] What to do if the model you want to create has a large number of fields
What to do if pip --user returns an error in a virtual environment created with pyenv
What to do if there is a decimal in python json .dumps
What to do if you couldn't send an email to Yahoo with Python.
What to do if you can't use scikit grid search in Python
What to do if you should have set an ssh key but are prompted for a password
What to do if pyenv install does not proceed with an error
What to do if an error occurs when importing numpy with VScode
What to do if you get a TypeError with numpy min, max
What to do if you can't install with pip in babun environment
What to do if fprintd requires a password when registering your fingerprint
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if an error occurs when loading a python project created with poetry into VS Code
What to do if a Unicode Encode Error occurs in Sublime Text Python
I tried to extract a line art from an image with Deep Learning
What to do if you get an error when installing python with pyenv
What to do if NotADirectoryError: [Errno 20] Not a directory:'xdg-settings' appears in jupyter notebook
What to do if a version error occurs in the selenium Chrome driver
What do you like about how to convert an array (list) to a string?
What to do if an SSL connection error (ssl.SSLError: [SSL: DH_KEY_TOO_SMALL]) occurs on Ubuntu 20.04
What to do when you want to receive files from a Windows client remotely
What to do if pipreqs results in UnicodeDecodeError
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do if rails s doesn't work
What to do if pip cannot be installed
What to do if atom autocomplete-python doesn't work
What to do if Docker-sync suddenly stops working
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
What to do if your Jupyter Notebook for beginners asks for a password or token
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if pvcreate produces a lot of WARNING and cannot be created
What to do if the print command itself causes an error in Maya python
What to do if you get an error when importing matplotlib in Python (Mac)
How to install and use pyenv, what to do if you can't switch python versions
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if Python does not switch from the System version in pyenv
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error