how to point correctly to static image in django

后端 未结 3 2178
再見小時候
再見小時候 2020-12-24 04:28

I have a template that renders an image:

{% load staticfiles %}

\"My

The im

3条回答
  •  我在风中等你
    2020-12-24 05:17

    Make folder "staticfiles" in root of your project where settings.py exists

    In staticfiles you can go this way..

    • css
    • js
    • images

    In settings.py

    STATIC_ROOT = os.path.join(PROJECT_DIR,'static')
    STATIC_URL = '/static/'
    
    STATICFILES_DIRS = (
                    os.path.join(PROJECT_DIR,'staticfiles'), # if your static files folder is named "staticfiles"
    )
    TEMPLATE_DIRS = (
                    os.path.join(PROJECT_DIR,'template'), # if your static files folder is named "template"
    )
    

    In base.html

     
    
    
    

    In other template files in which you include base.html

    {% extends "base.html" %}
    {% load static %}
    
    
    
    
    
    
    something

提交回复
热议问题