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 views


urlpatterns = [
    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 = False

ALLOWED_HOSTS = ['127.0.0.1']

....

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT=os.path.join(BASE_DIR, "media")
相关推荐
maqr_1101 天前
MySQL数据库迁移到云端如何保障安全_数据加密与SSL连接配置
jvm·数据库·python
苍何1 天前
万字保姆级教程:Hermes+Kimi K2.6 打造7x24h Agent军团
后端
我叫黑大帅1 天前
为什么map查找时间复杂度是O(1)?
后端·算法·面试
u0109147601 天前
MySQL如何限制触发器递归调用的深度_防止触发器死循环方法
jvm·数据库·python
weixin_381288181 天前
MySQL中如何使用HEX函数转换十六进制_MySQL进制转换函数
jvm·数据库·python
maqr_1101 天前
HTML怎么生成订单预览_HTML只读订单信息结构【操作】
jvm·数据库·python
sg_knight1 天前
设计模式实战:责任链模式(Chain of Responsibility)
python·设计模式·责任链模式
2301_803875611 天前
如何通过phpMyAdmin给WordPress所有用户发送全站通知_系统表插入
jvm·数据库·python
学弟1 天前
【内涵】深度学习中的三种变量及pytorch中对应的三种tensor
人工智能·pytorch·python
2301_777599371 天前
mysql如何进行数据库容量规划_评估磁盘空间增长趋势
jvm·数据库·python