如何将应用程序图像路径添加到urls.py?

时间:2015-03-20 19:46:17

标签: python django image

当我在localhost上运行我的应用程序时,我尝试显示使用adzone配置的随机横幅,但是当我加载我的主页时,我看不到我用于横幅的图像,问题是图像的路径是/media/adzone/bannerads/image.jpg,该路径由应用程序自动使用,我无法更改它。那么我怎么能告诉我的应用程序在那里寻找图像呢?

我的settings.py:

"""
Django settings for ciudad_tenis project.

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

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

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


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/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

TEMPLATE_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',
    'django.contrib.sites', 
    'news',
    'tournaments',
    'rules',
    'finalists',
    'courts',
    'adzone',
)

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

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    # and add request if you didn't do so already
    'django.core.context_processors.request',
    'adzone.context_processors.get_source_ip',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
)


FACEBOOK_APP_ID = '##################'
FACEBOOK_APP_SECRET = '##############################'

ROOT_URLCONF = 'ciudad_tenis.urls'

WSGI_APPLICATION = 'ciudad_tenis.wsgi.application'


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

LANGUAGE_CODE = 'es'

TIME_ZONE = 'America/Argentina/Buenos_Aires'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'ciudad_tenis',
    'HOST': '127.0.0.1',
    'PORT': '3306',
    'USER': 'root',
    'PASSWORD': '',
}}

SITE_ID = '1'

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['*']

# Static asset configuration
import os
BASE_DIR = os.path.abspath(os.path.dirname(__file__))


STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates'),
)

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

我的urls.py:

from django.conf.urls import patterns, include, url
from django.contrib import admin
from news import views
from django.views.generic import TemplateView
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # Examples:
    url(r'^$', TemplateView.as_view(template_name='home.html'), name="home"),
    # url(r'^blog/', include('blog.urls')),
    url(r'^novedades/', include('news.urls', namespace="news")),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^torneos/', include('tournaments.urls', namespace="tournaments")),
    url(r'^reglas/', include('rules.urls', namespace="rules")),
    url(r'^ganadores/', include('finalists.urls', namespace="finalists")),
    url(r'^canchas/', include('courts.urls', namespace="fields")),
    url(r'^adzone/', include('adzone.urls')),
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

我的应用结构:

myapp/
     myapp/
          static/
          templates/
          urls.py
          settings.py
          wsgi.py
          __init__.py
     adzone/
          bannerads/
          locale/
          south_migrations/
          templates/
          templatestags/
          models.py
          urls.py
          managers.py
          admin.py
          tests.py
          views.py
     other_app/
          migrations/
          static/
          templates/
          models.py
          admin.py
          urls.py
          views.py
          tests.py
          __init__.py

0 个答案:

没有答案