前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Django debug=False 时能找到静态文件的几种方式(静态文件找不到)

Django debug=False 时能找到静态文件的几种方式(静态文件找不到)

作者头像
卓越笔记
发布2023-02-18 14:02:32
1K0
发布2023-02-18 14:02:32
举报
文章被收录于专栏:卓越笔记

runserver 模式(临时用)

启动命令:django-admin runserver --insecure

--help: --insecure   Allows serving static files even if DEBUG is False.

代码语言:javascript
复制
(joyoo) yinzhuoqundeMacBook-Pro:joyoo yinzhuoqun$ Python manage.py runserver --help
usage: manage.py runserver [-h] [--version] [-v {0,1,2,3}]
                           [--settings SETTINGS] [--pythonpath PYTHONPATH]
                           [--traceback] [--no-color] [--ipv6] [--nothreading]
                           [--noreload] [--nostatic] [--insecure]
                           [addrport]

Starts a lightweight Web server for development and also serves static files.

positional arguments:
  addrport              Optional port number, or ipaddr:port

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on CommandError exceptions
  --no-color            Don't colorize the command output.
  --ipv6, -6            Tells Django to use an IPv6 address.
  --nothreading         Tells Django to NOT use threading.
  --noreload            Tells Django to NOT use the auto-reloader.
  --nostatic            Tells Django to NOT automatically serve static files
                        at STATIC_URL.
  --insecure            Allows serving static files even if DEBUG is False.

官方解释:

https://docs.djangoproject.com/zh-hans/2.2/ref/contrib/staticfiles/#cmdoption-runserver-insecure

使用--insecure选项强制使用 staticfiles 应用程式提供静态档案,即使 DEBUG 设定为False通过使用此功能,您可以确认严重无效以及可能不安全。这只适用于本地开发,应从不用于生产,并且仅当 staticfiles 应用程序位于项目的 INSTALLED_APPS 设置时可用。runserver--insecure 不适用于CachedStaticFilesStorage

单 uwsgi 模式

启动命令:uwsgi --http :8000 --file app/wsgi.py --static-map /static=/root/django/static_root

--help:  --static-map          map mountpoint to static directory (or file)

代码语言:javascript
复制
[root@VM_2_29_centos bin]# ./uwsgi --help | grep static-map
    --static-map                            map mountpoint to static directory (or file)
    --static-map2                           like static-map but completely appending the requested resource to the docroot

ini 配置

https://cloud.tencent.com/developer/article/2218915

nginx + uwsgi 模式(部署用)

请看:https://xieboke.net/article/61/

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-3-1 21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • runserver 模式(临时用)
  • 单 uwsgi 模式
  • nginx + uwsgi 模式(部署用)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档