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")
相关推荐
子兮曰4 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰4 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
默_笙4 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
爱勇宝4 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
qq_426003964 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫4 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
胡写代码4 天前
别再前后端各写一套表单校验了
java·后端
长沙三为智能科技4 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读4 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
大勇前进4 天前
原生 PHP 还是 Laravel?小项目到底要不要上框架
后端