回到顶部

Contents

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

runserver 模式(临时用)

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

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

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

[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

nginx + uwsgi 模式(部署用)

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

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!
前一篇: Celery ValueError: not enough values to unpack (expected 3, got 0) 的解决方法(windows)
下一篇: Django admin 多对多字段 过滤方法 及 保持横向显示(穿梭框)
captcha