Django/Gunicorn/Nginx:似乎提供了错误的JS文件

2024-05-13 02:17:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我的项目在当地工作

我已在远程服务器中部署了带有//的项目

我有一个带有选项列表的选择按钮(id=id\U patient)。当用户选择一个选项时,将使用ajax请求显示与该选项相关的信息。但在远程服务器上,不会显示信息

当我使用我的web浏览器调试工具(见图)查看时,它看起来并不是提供的好js文件

但在我服务器上的静态文件夹中,是好的js文件

// affichage des informations sur le patient sélectionné pour la ré-allocation
$("#id_patient").on("click", function (event) {

    var csrftoken = getCookie('csrftoken');

    if ($(this).val() != "") {
        $.ajax({
            type: "POST",
            url: $("#form_reallocation").data("patient-url"),
            data: {
                csrfmiddlewaretoken: csrftoken,
                'patient': $(this).val(),
            },
            dataType: 'html',
            success: function (data) {
                $("#information_patient").html(data);
            }

        });
    } else {
        $("#information_patient").children().remove();
    }

});

enter image description here

要收集新的静态文件,我有run python manage.py collectstatic和已收集的文件,但我有一条警告消息,指示静态文件中可能存在重复:

Found another file with the destination path 'randomization/js/script.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.

如何解决此问题

设置.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'crispy_forms',
    'widget_tweaks',
    'bootstrap4',

    'registration.apps.RegistrationConfig',
    'monitor.apps.MonitorConfig',
    'randomization.apps.RandomizationConfig',
    'parameters.apps.ParametersConfig',
    'unblind.apps.UnblindConfig',
    'pharmacy.apps.PharmacyConfig',
    'export.apps.ExportConfig',
    'randomization_pk.apps.RandomizationPkConfig',

    'django_extensions',
    'debug_toolbar',

    'partial_date',
    'safedelete',
    'simple_history',

]

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR,'static'),
    os.path.join(BASE_DIR,'randomization/static'),
    os.path.join(BASE_DIR,'unblind/static'),
    os.path.join(BASE_DIR,'pharmacy/static'),
)
STATIC_ROOT = '/home/test/intensetbm_static'

Tags: apps文件pathdjango服务器databaseos
1条回答
网友
1楼 · 发布于 2024-05-13 02:17:36

如果在生产模式下运行,且DEBUG=False,则必须配置Web服务器以提供静态文件

另一种选择是使用whitenoise作为中间件来服务静态文件,它不会处理Django管道来服务静态

尝试删除STATICFILES\u DIRS,默认情况下,Django在已安装的\u应用程序中查找所有“静态”文件夹,并使用到static\u ROOT的相对路径

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

之后,运行:

python manage.py collectstatic

再说一遍

相关问题 更多 >