代码之家  ›  专栏  ›  技术社区  ›  NejoFS

图像未在Django中从静态显示

  •  1
  • NejoFS  · 技术社区  · 2 年前

    以下是我提到图像的唯一代码:

    在HTML和CSS文件内部:

    <button type="submit" class="task-item-button">
    <img src="{% static 'x.svg' %}" alt="Close icon">
    </button>
    
    .task-item-button {
      position: absolute;
        top: 10px; /* Adjust the top position */
        right: 10px; /* Adjust the right position */
        width: 20px;
        height: 20px;
        color: red;
        padding: 0; 
        border: none; 
        background: none;
        border-radius: 8px;
        cursor: pointer;
        
    }
    .task-item-button img {
      width: 20px; /* Adjust the width of the image as needed */
      height: 20px; /* Adjust the height of the image as needed */
    }
    

    我确实有 {% load static %} 在顶部。

    除此之外,我在任何地方都没有提到这些图像。

    static的结构看起来像:

    enter image description here

    谢谢你的帮助。

    1 回复  |  直到 2 年前
        1
  •  1
  •   Mahammadhusain kadiwala    2 年前

    检查所有步骤:

    # Steps:
        # 1 - Create (static) folder in Root Directory of Project
        # 2 - Paste Your Static Files Folder in (static) Folder (js,css,images...etc)
        # 3 - Now Do Setting in (setting.py)
              STATIC_URL = '/static/'
    
              STATICFILES_DIRS = [os.path.join(BASE_DIR,'static')]
        # 4 - add {% load static %} tag on top of html page
        # 5 - Now use ({% static 'assets/image.jpg' %}) tag in HTML File for calling static files
        # 6 - Done