2021年1月2日星期六

Handing image file not found error in Django

I am trying to handle the image not found an error in Django by defining a custom view unhandle_urls. The way I am trying to do this is the following.

Define a URL pattern inside urls.py to match the image URL's pattern and route them to my custom view unhandle_urls

Here are my url patterns inside urls.py

 urlpatterns = [        ....        path(r'images/*', unhandle_urls, name="handling image not found urls"),        ...      ]  

However, I am still getting the same 404 error whenever any image is requested. Here is the error msg:

GET https:my-website-base-url/images/searchbox/desktop_searchbox_sprites318_hr.png 404 (Not Found)  

I am not sure what the problem is. My guess is that the url pattern r'images/*' is not matching to https:my-website-base-url/images/searchbox/desktop_searchbox_sprites318_hr.png, but when I try to look at this https://docs.djangoproject.com/en/3.1/topics/http/urls/, I could not find what's wrong with my approach.

Any type of help will be appreciated. Thanks in advance.

https://stackoverflow.com/questions/65546243/handing-image-file-not-found-error-in-django January 03, 2021 at 10:57AM

没有评论:

发表评论