首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Django静态文件在DEBUG=True和“收藏品”之后不一致

Django静态文件在DEBUG=True和“收藏品”之后不一致
EN

Stack Overflow用户
提问于 2022-06-14 13:13:58
回答 2查看 250关注 0票数 1

我的"Select {s} { model }s“操作(在Django管理中查看模型页时应该在actions栏中)在生产中不起作用。

预期行为,如在本地运行的DEBUG=Truelocal_settings.py中记录的那样:

在使用DEBUG=False在本地运行时,对暂存部署和本地运行的行为:

我的模板在本地运行runserver命令与DEBUG=True之间的静态文件之间存在不一致性问题,而不是在运行collectstatic之后运行相同的代码库,然后在我的设置中使用DEBUG=False运行它。

在检查页面时,静态文件中的差异在列出的源中也很明显。正确工作:

不正确地工作:

运行collectstatic命令将给出以下输出:

代码语言:javascript
运行
复制
Loading .env environment variables...
Found another file with the destination path 'admin/js/actions.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin/js/admin/RelatedObjectLookups.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
Found another file with the destination path 'admin/js/admin/DateTimeShortcuts.js'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.

但是在本地,actions.jsactions.min.js都存在于我的静态文件文件夹中。我不想在产品部署上启动调试,但目前还不知道如何解决这个问题。所有的帮助都将不胜感激。

编辑:我的设置文件是被请求的,所以这里有一个版本(清除了敏感数据):

代码语言:javascript
运行
复制
import os

DEBUG = False
MAINTENANCE_MODE = False
TEMPLATE_DEBUG = DEBUG
DEPLOYMENT_NAMESPACE = os.getenv("K8_NAMESPACE", "")
DEPLOY_LOCATION = "testing"
SESSION_COOKIE_AGE = 604800  # A week
DATABASES: dict = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "HOST": "127.0.0.1",
        "NAME": f"[DB_NAME]",
        "USER": "postgres",
        "PASSWORD": "[PASSWORD]",
    }
}
DATABASES["readonly"] = DATABASES["default"].copy()
DATABASES["readonly"]["USER"] += "_readonly"
DATABASES["readonly"]["TEST"] = {"MIRROR": "default"}

UNICORN_VERSION = os.getenv("UNICORN_VERSION", "[COMPANY_NAME]")

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = PROJECT_PATH.joinpath("static")

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = "/static/"

# Additional locations of static files
STATICFILES_DIRS = (
    PROJECT_PATH.joinpath("versions", UNICORN_VERSION, "static"),
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
    "django.contrib.staticfiles.finders.FileSystemFinder",
)

LOCALE_PATHS = [PROJECT_PATH.joinpath("locale")]

# When a version defines a locale folder, it becomes the main
LOCALE_PATHS = getattr(version_settings, "LOCALE_PATHS", LOCALE_PATHS)

INSTALLED_APPS = [
    "django.contrib.contenttypes",
    "django.contrib.auth",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_otp",
    "django_otp.plugins.otp_static",
    "django_otp.plugins.otp_totp",
    "two_factor",
    "grappelli",
    "grappelli_filters",
    "django.contrib.admin",
    "rangefilter",
    "admin_numeric_filter",
    "admin_auto_filters",
    "api",
]
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72617621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档