Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Django/React部署仅在设置DEBUG=True&;静态文件\u DIRS不是一个列表_Reactjs_Django_Deployment_Pythonanywhere - Fatal编程技术网

Reactjs Django/React部署仅在设置DEBUG=True&;静态文件\u DIRS不是一个列表

Reactjs Django/React部署仅在设置DEBUG=True&;静态文件\u DIRS不是一个列表,reactjs,django,deployment,pythonanywhere,Reactjs,Django,Deployment,Pythonanywhere,尝试将带有django后端的react前端部署到Pythonywhere(PA),但通过以下3种设置获得以下结果: DEBUG=True,STATICFILES\u DIRS=[os.path.join(BASE\u DIR,'build/static')]-(空白白屏) PA服务器日志: File "/home/coot3/.virtualenvs/venv/lib/python3.8/posixpath.py", line 76, in join a = os

尝试将带有django后端的react前端部署到Pythonywhere(PA),但通过以下3种设置获得以下结果:

  • DEBUG=True,STATICFILES\u DIRS=[os.path.join(BASE\u DIR,'build/static')]-(空白白屏)
  • PA服务器日志:

      File "/home/coot3/.virtualenvs/venv/lib/python3.8/posixpath.py", line 76, in join
        a = os.fspath(a)
    TypeError: expected str, bytes or os.PathLike object, not list
    
    Chrome控制台:

    Refused to execute script from 'http://mysite.pythonanywhere.com/static/js/main.446b4eaa.chunk.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
    
    Refused to execute script from 'http://mysite.pythonanywhere.com/static/js/main.446b4eaa.chunk.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
    
  • DEBUG=True,STATICFILES\u DIRS=os.path.join(BASE\u DIR,‘build/static’)-(网站按预期工作)

  • DEBUG=False,STATICFILES\u DIRS=os.path.join(BASE\u DIR,'build/static')-(空白白屏)

  • PA服务器日志中没有问题

    Chrome控制台:

    Refused to execute script from 'http://mysite.pythonanywhere.com/static/js/main.446b4eaa.chunk.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
    
    Refused to execute script from 'http://mysite.pythonanywhere.com/static/js/main.446b4eaa.chunk.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
    
    我的django根文件夹中有react app build文件夹,链接到react index.html,作为URL.py中的模板视图。这是我的settings.py:

    from pathlib import Path
    import os
    import environ
    
    env = environ.Env(
        DEBUG=(bool, False)
    )
    
    environ.Env.read_env()
    
    DEBUG = False
    
    SECRET_KEY = env('SECRET_KEY')
    
    BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
    
    HOSTS = ['coot3.pythonanywhere.com']
    
    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'store',
        'corsheaders',
        'rest_framework',
    ]
    
    MIDDLEWARE = [
        'corsheaders.middleware.CorsMiddleware',
        '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 = 'mysite.urls'
    
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [os.path.join(BASE_DIR, 'build')],
            '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 = 'mysite.wsgi.application'
    
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': BASE_DIR / 'db.sqlite3',
        }
    }
    
    
    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]
    
    LANGUAGE_CODE = 'en-us'
    
    TIME_ZONE = 'UTC'
    
    USE_I18N = True
    
    USE_L10N = True
    
    USE_TZ = True
    
    STATIC_URL = '/static/'
    
    STATICFILES_DIRS = os.path.join(BASE_DIR, 'build/static')
    
    STATIC_ROOT = os.path.join(BASE_DIR, 'static')
    
    MEDIA_URL = '/media/'
    
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    
    CORS_ORIGIN_ALLOW_ALL = True
    
    EMAIL_USE_TLS = True
    
    EMAIL_HOST = 'smtp.gmail.com'
    
    EMAIL_PORT = 587
    
    EMAIL_HOST_USER = env('EMAIL_HOST_USER')
    
    EMAIL_HOST_PASSWORD = env('EMAIL_HOST_PASSWORD')
    

    Django在不处于调试模式时不提供静态文件。因此,您必须配置web应用程序的静态文件映射以提供静态文件。Pythonywhere帮助页面上有大量关于静态文件的帮助。

    Django在不处于调试模式时不提供静态文件。因此,您必须配置web应用程序的静态文件映射以提供静态文件。Pythonywhere帮助页面上有大量关于静态文件的帮助