python - Django 1.5 (MEDIA_ROOT, TEMPLATE_DIRS) -


i'm new django (1.5) , i'm having hard time relative configuration of media folder in media_root. can't charge files .css, .js, .jpg in project. receive following msg in shell:

[06/oct/2013 19:12:01] "get /media/css/style.css http/1.1" 404 4140

this tree of project:

  • _3ms
    • _3ms
    • apps
    • media
      • css
      • js
      • images
    • template

this configuration

setting.py

media_root = os.path.join(os.path.dirname(__file__), 'media/')  media_url = '/media/'  static_root = ''  static_url = '/static/'  staticfiles_dirs = ( )   staticfiles_finders = (     'django.contrib.staticfiles.finders.filesystemfinder',     'django.contrib.staticfiles.finders.appdirectoriesfinder', #    'django.contrib.staticfiles.finders.defaultstoragefinder', )  template_loaders = (     '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',     # uncomment next line simple clickjacking protection:     # 'django.middleware.clickjacking.xframeoptionsmiddleware', )  root_urlconf = '_3ms.urls'  wsgi_application = '_3ms.wsgi.application'  template_dirs = os.path.dirname(__file__), 'templates', ) 

home.html

{% block css %}<link href="/media/css/style.css" rel="stylesheet">{% endblock %} 

thank in advance

you typically use static_url static assets css , javascript. media used admin or user uploaded files.

so fill out staticfiles_dir , use static_url in templates.

settings:

import os.path  project_path = os.path.abspath(os.path.join(os.path.split(__file__)[0], '..'))  staticfiles_dirs = [     '/path/to/your/static/assets',     os.path.abspath(os.path.join(project_path, '..', 'static')), ] 

template:

{% block css %}<link href="{{ static_url }}css/style.css" rel="stylesheet">{% endblock %} 

i'm assuming using django devserver.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -