settings.py
import os.path
import posixpath
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
SERVE_MEDIA = DEBUG
COMPRESS = False
INTERNAL_IPS = [
"127.0.0.1",
]
ADMINS = [
]
MANAGERS = ADMINS
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "dev.db",
"USER": "",
"PASSWORD": "",
"HOST": "",
"PORT": "",
}
}
TIME_ZONE = "US/Eastern"
LANGUAGE_CODE = "en-us"
SITE_ID = 1
USE_I18N = True
MEDIA_ROOT = os.path.join(PROJECT_ROOT, "static")
MEDIA_URL = "/site_media/media/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")
STATIC_URL = "/site_media/static/"
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "static"),
os.path.join(PROJECT_ROOT, "media"),
]
STATICFILES_FINDERS = [
"staticfiles.finders.FileSystemFinder",
"staticfiles.finders.AppDirectoriesFinder",
"staticfiles.finders.LegacyAppDirectoriesFinder",
"compressor.finders.CompressorFinder",
]
ADMIN_MEDIA_PREFIX = posixpath.join(STATIC_URL, "admin/")
COMPRESS_OUTPUT_DIR = "cache"
SECRET_KEY = "HIDDEN"
TEMPLATE_LOADERS = [
"django.template.loaders.filesystem.load_template_source",
"django.template.loaders.app_directories.load_template_source",
]
MIDDLEWARE_CLASSES = [
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django_openid.consumer.SessionConsumer",
"django.contrib.messages.middleware.MessageMiddleware",
"pinax.apps.account.middleware.LocaleMiddleware",
"pagination.middleware.PaginationMiddleware",
"pinax.middleware.security.HideSensistiveFieldsMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
]
ROOT_URLCONF = "ezstyler.urls"
TEMPLATE_DIRS = [
os.path.join(PROJECT_ROOT, "templates"),
]
TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"staticfiles.context_processors.static",
"pinax.core.context_processors.pinax_settings",
"pinax.apps.account.context_processors.account",
"notification.context_processors.notification",
"announcements.context_processors.site_wide_announcements",
]
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.messages",
"django.contrib.humanize",
"pinax.templatetags",
"pinax_theme_foundation",
"notification",
"staticfiles",
"compressor",
"debug_toolbar",
"mailer",
"django_openid",
"timezones",
"emailconfirmation",
"announcements",
"pagination",
"idios",
"metron",
"pinax.apps.account",
"pinax.apps.signup_codes",
"about",
"profiles",
"outfits",
]
FIXTURE_DIRS = [
os.path.join(PROJECT_ROOT, "fixtures"),
]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
EMAIL_BACKEND = "mailer.backend.DbBackend"
ABSOLUTE_URL_OVERRIDES = {
"auth.user": lambda o: "/profiles/profile/%s/" % o.username,
}
AUTH_PROFILE_MODULE = "profiles.Profile"
NOTIFICATION_LANGUAGE_MODULE = "account.Account"
ACCOUNT_OPEN_SIGNUP = True
ACCOUNT_USE_OPENID = False
ACCOUNT_REQUIRED_EMAIL = False
ACCOUNT_EMAIL_VERIFICATION = False
ACCOUNT_EMAIL_AUTHENTICATION = False
ACCOUNT_UNIQUE_EMAIL = EMAIL_CONFIRMATION_UNIQUE_EMAIL = False
AUTHENTICATION_BACKENDS = [
"pinax.apps.account.auth_backends.AuthenticationBackend",
]
LOGIN_URL = "/account/login/"
LOGIN_REDIRECT_URLNAME = "what_next"
LOGOUT_REDIRECT_URLNAME = "home"
EMAIL_CONFIRMATION_DAYS = 2
EMAIL_DEBUG = DEBUG
DEBUG_TOOLBAR_CONFIG = {
"INTERCEPT_REDIRECTS": False,
}
try:
from local_settings import *
except ImportError:
pass
And urls.py if this helps:
from django.conf.urls.defaults import *
from outfits.views import *
import settings
urlpatterns = patterns("",
url(r'^$', outfit_list, name='outfit_list'),
url(r'^new/$', outfit_create, name='outfit_create'),
url(r'^detail/(\d+)/$', outfit_detail, name='outfit_detail'),
url(r'^update/(\d+)/$', outfit_update, name='outfit_update'),
url(r'^delete/(\d+)/$', outfit_delete, name='outfit_delete'),
url(r'^detail/(\d+)/add/confirm/$', product_confirm, name='product_confirm'),
url(r'^outfit_displayImg/$', outfits_displayImg),
url(r'^detail/(\d+)/add/$', product_add, name='product_add'),
url(r'^detail/(\d+)/update/(\d+)$', product_update, name='product_update'),
url(r'^detail/(\d+)/delete/(\d+)$', product_delete, name='product_delete'),
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^site_media/media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)
So, in my template {{MEDIA_URL}} {{p.images}} the correct URL is returned http://127.0.0.1:8000/site_media/media/products/co_macysLogo3.gif , but when I open it, I do not get the page found.
There is a file, so I'm not sure why it complains. I looked at 3 or 4 other questions about SO that are similar to mine, but none of their answers resolved my issue. Itβs strange that my {{STATIC_URL}} works fine, but not {{MEDIA_URL}}. Of course, I would use STATIC_URL if I could, just to make my application work, but, unfortunately, the Django ImageField upload_to parameter only uploads images to the media folder.
: MEDIA_ROOT MEDIA_ROOT = os.path.join(PROJECT_ROOT, "static") {{STATIC_URL}} {{p.images}} . , . , Django MEDIA_URL.