1,Debug=True 调试模式
Test/Test/settings.py
DEBUG = True
...
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_URL = '/static/'
![](https://img-blog.csdnimg.cn/direct/bef0f3fcd34e40c08ba84da671383169.png)
![](https://img-blog.csdnimg.cn/direct/03645826e07e401b98d1379448e508ee.png)
1.1 创建静态文件
Test/static/6/images/Sni1.png
1.2 添加视图函数
Test/app6/views.py
from django.shortcuts import render
# Create your views here.
def welcome(request):
return render(request, '6/welcome.html')
def test_img(request):
return render(request, '6/test_img.html')
![](https://img-blog.csdnimg.cn/direct/8456871530bc4b82b5eb1f76b119c807.png)
1.3 添加路由地址
Test/app6/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('welcome', views.welcome, name='welcome'),
path('test_img', views.test_img, name='test_img'),
]
![](https://img-blog.csdnimg.cn/direct/47bf7fd43e6847bc93e96c4bddea31c2.png)
1.4 访问页面
http://127.0.0.1:8000/app6/test_img
![](https://img-blog.csdnimg.cn/direct/e39e63d5630c4c1ea9146d646266d129.png)
![](https://img-blog.csdnimg.cn/direct/950a85b07df1409d813723f6836aff76.png)
2,Debug=False 生产模式
Test/Test/settings.py
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1']
....
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT=os.path.join(BASE_DIR, "media")