我在Django創建了一個在線商店。它在我的電腦上運行良好。我已將它移到共享主機上,但現在我無法上傳任何內容。我可以在數據庫中添加新的信息,但沒有圖像。我無法在我的Django網站上上傳文件
我總是得到404錯誤。我在設置中正確配置了MEDIA_URL和MEDIA_ROOT。
誰知道如何解決這個問題?
我在Django創建了一個在線商店。它在我的電腦上運行良好。我已將它移到共享主機上,但現在我無法上傳任何內容。我可以在數據庫中添加新的信息,但沒有圖像。我無法在我的Django網站上上傳文件
我總是得到404錯誤。我在設置中正確配置了MEDIA_URL和MEDIA_ROOT。
誰知道如何解決這個問題?
我的settings.py文件(這是我使用Django和Python初體驗):
「」」
Django settings for public project.
Generated by 'django-admin startproject' using Django 1.8.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
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/1.8/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 = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'public.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'public.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_URL = '/media/'
MEDIA_ROOT = "/home/scrisoft/public_html/bushare/app/static/media/"
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = "http://bushare.scrisoft.com/app/static/"
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
'/home/scrisoft/public_html/bushare/app/static/',
)
我的網站的地址是http://bushare.scrisoft.com/
Webserver配置?如果它使用django runserver在網站上運行,那麼它可能是web服務器 –
什麼是:$ ls -l/home/scrisoft/public_html/bushare/app/static/media /? –
是上傳所有圖像的文件夾。這裏 – user3062975
我有這個錯誤,因爲我已經在我的電腦上使用postgressql數據庫,但在主機上我手動創建了一個mysql數據庫,現在我通過移動這個應用程序來支持postgressql支持,解決了這個錯誤
服務器媒體目錄上的權限?你需要提供更多的細節。 –
只是爲了確認'DEBUG'模式現在是False,對吧? – Yeo
DEBUG是真的。媒體目錄有755個權限。 – user3062975