Access pictures in static resources ( Just put it in static Pictures in the folder )
Static resources store some pages that need to be loaded frequently and are generally not defined by users , So it will not change where it is stored , The folder name is defined as static, Position in Yours app Next
access :
stay settings.py The configuration at the bottom of the file
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'collected_static')
Type in the browser https://host:port/static/img.png You can access the... In your static resources folder img.png picture
When we have a lot of pictures , If you also put it in static Under the folder , The system will be overloaded , The operation is not smooth and even crashes , So it is necessary to define a folder for storing pictures , These pictures will not be loaded into memory as the program runs , It is called only when accessing .
access :
Define a routing function
def ilcimg(request):
imagepath = "photo/123.png"
image_data = open(imagepath,"rb").read()
return HttpResponse(image_data, content_type="image/png")
By configuring to urls.py in , Access to url Address to get the picture
stay doc root directories creating photo/ Deposit 123.png, then url.py It specifies the access routing function .