django2 + python3 显示静态文件中的图片

之前一直搞不出来 是因为图片的问题,步骤也就是固定的几步,到位了就差不多成了
文件夹结构:
. ├── HelloWorld │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── settings.cpython-36.pyc │ │ ├── urls.cpython-36.pyc │ │ └── wsgi.cpython-36.pyc │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── hello │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ ├── admin.cpython-36.pyc │ │ ├── models.cpython-36.pyc │ │ └── views.cpython-36.pyc │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── __init__.py │ │ └── __pycache__ │ │ └── __init__.cpython-36.pyc │ ├── models.py │ ├── static │ │ └── hello │ │ └── 6.png │ ├── templates │ │ └── index.html │ ├── tests.py │ └── views.py └── manage.py
settings.py文件加这两句
STATIC_URL = '/static/' MEDIA_ROOT = os.path.join(BASE_DIR, 'static/')

views.py文件加

from django.shortcuts import render

from django.shortcuts import render
from django.http import HttpResponse

def showImg(request):
    return render(request,'index.html')

urls.py

from django.contrib import admin
from django.urls import path
from hello import views
from django.conf.urls.static import static
from . import settings

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.showImg)
]

index.html文件

一定要写

{% load staticfiles %} 这句
<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    {% load staticfiles %}
</head>


<body>
<h1>显示一张本地图片</h1>
<img src="{% static '6.png' %}" width="500" height="500" alt="图片无法显示">
</body>
</html>