您的位置:首页 > 文旅 > 美景 > Django 配置静态文件

Django 配置静态文件

2024/10/5 19:16:45 来源:https://blog.csdn.net/qq_26086231/article/details/140070288  浏览:    关键词:Django 配置静态文件

1,Debug=True 调试模式

Test/Test/settings.py

DEBUG = True...STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static'),]
STATIC_URL = '/static/'

 

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')

1.3 添加路由地址

Test/app6/urls.py

from django.urls import path
from . import viewsurlpatterns = [path('welcome', views.welcome, name='welcome'),path('test_img', views.test_img, name='test_img'),
]

1.4 访问页面

http://127.0.0.1:8000/app6/test_img

 

 

2,Debug=False 生产模式

Test/Test/settings.py

DEBUG = FalseALLOWED_HOSTS = ['127.0.0.1']....STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT=os.path.join(BASE_DIR, "media")

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com