Django uses image delayed loading to cause a 404 error in the background,

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.