python - New Django App MEDIA_URL pathing incorrect -



python - New Django App MEDIA_URL pathing incorrect -

so, i've created new app in django via python manage.py startapp foo

my new app not load files in /site_media/ directory, via {{ media_url }}. attempting path app's directory, not /site_media/ directory.

example: instead of loading http://sitename/site_media/bootstrap/bootstrap.min.css

it tries load http://sitename/foo/bootstrap/bootstrap.min.css

here snippet settings.py defines media_url

media_url = '/site_media/'

i can forcefulness files load correctly in app replacing {{ media_url }} /site_media/ in base.html , show_foo.html, breaks pathing on rest of site.

i'm not sure else see seek , diagnose issue, i'm stumped!

in case: urls.py in app directory

#!/usr/bin/python # -*- coding: utf8 -*- django.conf.urls.defaults import * urlpatterns = patterns('foo_web.foo_track.views', url('^$','view_foo_track',name='foo_home'), url('^newentry/(?p<entry_id>\d+)$','write_form_data',name='foo_track_new'), )

settings.py edit*removed comments readability

import os current_dir = os.path.abspath(os.path.dirname(__file__)) os import sys, path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) import run_server cherry_config,django_config = run_server.get_web_server_parameters() debug = django_config['debug'] template_debug = django_config['template_debug'] cache_mode = django_config['cache_mode'] db = django_config['db'] host = django_config['host'] login_url = '/' logout_url = '/' databases = { 'default': { 'engine': 'django.db.backends.postgresql_psycopg2', 'name': '%s' % db, 'user': 'postgres', 'password': '*****', 'host': '%s' % host, 'port': '5432', } } caches = { 'default': { 'backend': cache_mode, 'location': 'my_cache_table', 'timeout': 1800, 'options': { 'max_entries': 10000 } } } admins = ( ('**', '**'), ) managers = admins #~ email_backend = 'django.core.mail.backends.smtp.emailbackend' default_from_email = '**' server_email = '**' email_use_tls = true email_host = "**" email_host_user = "**" email_host_password = "**" time_zone = 'america/chicago' language_code = 'en-us' #~ gettext = lambda s: s #~ languages = ( #~ ('de', gettext('german')), #~ ('en', gettext('english')), #~ ) site_id = 1 use_i18n = true use_l10n = true use_tz = true media_root = current_dir + '/media/' media_url = '/site_media/' static_root = current_dir + '/media/static/' static_url = '/site_static/' staticfiles_dirs = ( # set strings here, "/home/html/static" or "c:/www/django/static". ) staticfiles_finders = ( 'django.contrib.staticfiles.finders.filesystemfinder', 'django.contrib.staticfiles.finders.appdirectoriesfinder', # 'django.contrib.staticfiles.finders.defaultstoragefinder', ) secret_key = '***' if debug: template_loaders = ( 'django.template.loaders.filesystem.loader', 'django.template.loaders.app_directories.loader', # 'django.template.loaders.eggs.loader', ) else: template_loaders = ( ('django.template.loaders.cached.loader', ( 'django.template.loaders.filesystem.loader', 'django.template.loaders.app_directories.loader', )), # 'django.template.loaders.eggs.loader', ) middleware_classes = ( 'django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware', 'sensei_web.middleware.filterpersistmiddleware', # uncomment next line simple clickjacking protection: # 'django.middleware.clickjacking.xframeoptionsmiddleware', #~ 'sensei_web.middleware.profilemiddleware' #~ 'django.middleware.cache.updatecachemiddleware', #~ 'django.middleware.common.commonmiddleware', #~ 'django.middleware.cache.fetchfromcachemiddleware', ) root_urlconf = 'sensei_web.urls' wsgi_application = 'sensei_web.wsgi.application' template_dirs = ( current_dir + '/templates', ) installed_apps = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', # uncomment next line enable admin: 'django.contrib.admin', # uncomment next line enable admin documentation: # 'django.contrib.admindocs', 'foo.foo', 'foo.foo', #~ 'foo.foo', 'foo.foo', 'foo.foo', 'foo', 'foo.foo', 'foo.foo_track', ) account_activation_days = 7 logging = { 'version': 1, 'disable_existing_loggers': false, 'filters': { 'require_debug_false': { '()': 'django.utils.log.requiredebugfalse' } }, 'handlers': { 'mail_admins': { 'level': 'error', 'filters': ['require_debug_false'], 'class': 'django.utils.log.adminemailhandler' } }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'error', 'propagate': true, }, } }

thanks help! turns out error made :( interesting consequences though.

i noticed funny in logs a (% csrf_token %) used in template, context did not provide value. uaually caused not using requestcontext.

lo , behold, in views.py line incorrect: return render_to_response('foo_track/foo_track_show.html',{'access':access})

it should have had requestcontext(request) this: return render_to_response('foo_track/foo_track_show.html',{'access':access},requestcontext(request))

and works. sheesh!

python django

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -