将Django应用程序部署到PythonAnywhere时找不到静态CSS文件/图像

时间:2020-07-01 18:52:45

标签: python css django web-deployment pythonanywhere

我无法使用PythonAnywhere部署Django产品组合。我已经成功部署了该应用程序,但是找不到我的静态图像和CSS文件。

settings.py:

"""
Django settings for portproject project.

Generated by 'django-admin startproject' using Django 3.0.7.

For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '********************************************'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['pbuzzo.pythonanywhere.com']


# Application definition

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

]

SITE_ID = 1

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',
]

STATIC_URL = '/portapp/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

ROOT_URLCONF = 'portproject.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(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 = 'portproject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

# Configure Django App for Heroku.


urls.py:

from django.contrib import admin
from django.urls import path
from portapp.urls import urlpatterns as myapp_urls
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += myapp_urls

/var/www/pbuzzo_pythonanywhere_com_wsgi.py:

# This file contains the WSGI configuration required to serve up your
# web application at http://pbuzzo.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#

# +++++++++++ GENERAL DEBUGGING TIPS +++++++++++
# getting imports and sys.path right can be fiddly!
# We've tried to collect some general tips here:
# https://help.pythonanywhere.com/pages/DebuggingImportError



# +++++++++++ VIRTUALENV +++++++++++
# If you want to use a virtualenv, set its path on the web app setup tab.
# Then come back here and import your application object as per the
# instructions below


# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys

## assuming your django settings file is at '/home/pbuzzo/mysite/mysite/settings.py'
## and your manage.py is is at '/home/pbuzzo/mysite/manage.py'
path = '/home/pbuzzo/se-portfolio'
if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'portproject.settings'

# then:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()


var / log / pbuzzo.pythonanywhere.com.error.log:

2020-07-01 00:57:27,901: Not Found: /static/styles.css
2020-07-01 00:57:29,147: Not Found: /favicon.ico
2020-07-01 00:57:31,701: Not Found: /static/styles.css
2020-07-01 00:57:31,710: Not Found: /static/img/htmlcsslogo.png
2020-07-01 00:57:31,813: Not Found: /static/img/pythonlogo.jpg
2020-07-01 00:57:31,816: Not Found: /static/img/reactjslogo.webp
2020-07-01 00:57:31,847: Not Found: /static/img/npmlogo.png
2020-07-01 00:57:31,853: Not Found: /static/img/djangologo.png
2020-07-01 00:57:31,858: Not Found: /static/img/httplogo.png
2020-07-01 00:57:31,864: Not Found: /static/img/apilogo.png
2020-07-01 00:57:31,869: Not Found: /static/img/databaselogo.png
2020-07-01 00:57:31,872: Not Found: /static/img/responsivelogo.png
2020-07-01 00:57:34,409: Not Found: /static/styles.css
2020-07-01 00:58:13,496: Not Found: /static/styles.css
2020-07-01 01:00:02,081: Not Found: /static/styles.css
2020-07-01 01:09:38,457: Not Found: /static/styles.css
2020-07-01 01:10:40,440: Not Found: /static/styles.css
2020-07-01 01:12:19,779: Not Found: /static/styles.css
2020-07-01 01:12:22,293: Not Found: /static/styles.css
2020-07-01 01:12:22,408: Not Found: /static/img/charcode.gif
2020-07-01 01:12:22,431: Not Found: /static/img/kwitter.gif
2020-07-01 01:12:22,451: Not Found: /static/img/craigscrape.gif
2020-07-01 01:12:22,455: Not Found: /static/img/phonestore.gif
2020-07-01 01:12:22,460: Not Found: /static/img/bookstore.gif
2020-07-01 01:12:23,384: Not Found: /static/styles.css
2020-07-01 01:12:23,498: Not Found: /static/img/htmlcsslogo.png
2020-07-01 01:12:23,517: Not Found: /static/img/reactjslogo.webp
2020-07-01 01:12:23,530: Not Found: /static/img/httplogo.png
2020-07-01 01:12:23,556: Not Found: /static/img/pythonlogo.jpg
2020-07-01 01:12:23,571: Not Found: /static/img/djangologo.png
2020-07-01 01:12:23,579: Not Found: /static/img/apilogo.png
2020-07-01 01:12:23,582: Not Found: /static/img/databaselogo.png
2020-07-01 01:12:23,586: Not Found: /static/img/npmlogo.png
2020-07-01 01:12:23,590: Not Found: /static/img/responsivelogo.png
2020-07-01 01:12:24,771: Not Found: /static/styles.css
2020-07-01 01:12:24,787: Not Found: /static/img/charcode.gif
2020-07-01 01:12:24,894: Not Found: /static/img/kwitter.gif
2020-07-01 01:12:24,909: Not Found: /static/img/craigscrape.gif
2020-07-01 01:12:24,937: Not Found: /static/img/phonestore.gif
2020-07-01 01:12:24,956: Not Found: /static/img/bookstore.gif
2020-07-01 01:12:27,723: Not Found: /static/styles.css
2020-07-01 01:12:27,729: Not Found: /static/img/htmlcsslogo.png
2020-07-01 01:12:27,829: Not Found: /static/img/reactjslogo.webp
2020-07-01 01:12:27,835: Not Found: /static/img/pythonlogo.jpg
2020-07-01 01:12:27,839: Not Found: /static/img/djangologo.png
2020-07-01 01:12:27,844: Not Found: /static/img/httplogo.png
2020-07-01 01:12:27,849: Not Found: /static/img/apilogo.png
2020-07-01 01:12:27,852: Not Found: /static/img/databaselogo.png
2020-07-01 01:12:27,864: Not Found: /static/img/npmlogo.png
2020-07-01 01:12:27,870: Not Found: /static/img/responsivelogo.png
2020-07-01 01:12:29,009: Not Found: /static/styles.css
2020-07-01 01:16:17,812: Not Found: /static/styles.css
2020-07-01 01:18:02,372: Not Found: /static/styles.css
2020-07-01 01:18:04,945: Not Found: /static/styles.css
2020-07-01 01:26:07,489: Not Found: /static/styles.css
2020-07-01 01:26:29,470: Not Found: /static/styles.css
2020-07-01 01:26:46,904: Not Found: /static/styles.css
2020-07-01 01:27:31,250: Not Found: /static/styles.css
2020-07-01 01:27:31,388: Not Found: /static/img/charcode.gif
2020-07-01 01:27:31,391: Not Found: /static/img/kwitter.gif
2020-07-01 01:27:31,422: Not Found: /static/img/craigscrape.gif
2020-07-01 01:27:31,426: Not Found: /static/img/phonestore.gif
2020-07-01 01:27:31,429: Not Found: /static/img/bookstore.gif
2020-07-01 01:27:36,317: Not Found: /static/styles.css

静态文件夹位于/se-portfolio/portapp/static,静态文件夹包含一个img文件夹和一个styles.css文件。

0 个答案:

没有答案