如何在Windows 10 IIS上显示Django静态文件

gopyfrb3  于 2023-10-19  发布在  Windows
关注(0)|答案(1)|浏览(160)

我试图在Windows 10上部署Django应用程序,我的应用程序工作正常,但Django静态文件不服务。
这里是我在Windows10 IIS服务器上配置的设置

Web配置

<appSettings>
        <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
        <add key="PYTHONPATH" value="E:\django\crm\crm\crm" />
        <add key="DJANGO_SETTINGS_MODULE" value="crm.settings" />
    </appSettings>

    <system.webServer>
        <handlers>
            <remove name="crm" />
            <add name="crm" path="*" verb="*" modules="FastCgiModule" scriptProcessor="E:\django\crm\crm\crm\env\Scripts\python.exe|E:\django\crm\crm\crm\env\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
    </system.webServer>
</configuration>

添加网站

FASTCGI设置

Map

设置Py

from pathlib import Path
import os
BASE_DIR = Path(__file__).resolve().parent.parent
DEBUG = False
ALLOWED_HOSTS = ['192.168.11.59','127.0.0.1']

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

    'base.apps.BaseConfig',

    'dbbackup',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'crm.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR ,'templates'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'crm.wsgi.application'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_TZ = True

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
STATICFILES_DIRS = [BASE_DIR /'static']

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media')

我不知道为什么它不工作。我已经正确设置了static_url和static_root,url.py指导我如何修复它。

wz3gfoph

wz3gfoph1#

你可以试试这个方法:

  • 转到IIS服务器->右键单击网站->添加虚拟目录
  • 然后导航到项目中所有静态文件所在的文件夹。

相关问题