Django uses image delayed loading to cause a 404 error in the background,
Environment django 1.10.6
Origin
Today, I received a task to solve useless errors in terminal full screen logs. Django will try its best to accurately report the error location, but some complicated and deep-level errors have their own error logs which are insufficient, but many logs are not valid.
Process
If too many background logs are useless, I directly go to the browser to view the console access information and get the following prompt:
Go directly to the background to match this error: undefined. Based on this error, we cannot locate the specific problem. I found that this problem may occur when I access a specific page, but no error occurs if I change the page. Now, I am tracking this page. I try to replace the page and locate an html code that will cause this error:
I am surprised that an img tag will cause a wrong backend access address, but I have no idea why. I tried to replace the src of this img and the results were still the same.
You can find the problem by using firebug debugging ,:
Follow the call stack prompts to search for related js such
The final result is that the image address is asynchronously loaded. After the image address is asynchronously loaded, the img src becomes undefined, causing the backend to access a non-existent address.
Solution
Process the src value before use.
Function imageLoaded (obj, src) {var img = new Image (); if (src = undefined) {src = '';} img. onload = function () {obj. src = src;}; img. src = src ;}