python - Static content in Django -
i trying load static content django have upgraded django 1.4 project has been successfuly deployed , unable find images , static content of project.
please find settings.py file
# django settings dataentry project. import sys import os path import path settings_file_folder = path(__file__).parent.abspath() sys.path.append(settings_file_folder.joinpath("libs").abspath()) debug = true template_debug = debug internal_ips = ("127.0.0.1", "localhost", "192.168.100.102") admins = ( (" hello world ", "hello.world@gmail.com"), ) managers = admins databases = { 'default': { 'engine': 'django.db.backends.mysql', # add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'name': 'gototest', # or path database file if using sqlite3. 'user': 'root', # not used sqlite3. 'password': 'root', # not used sqlite3. 'host': 'localhost', # set empty string localhost. not used sqlite3. 'port': '', # set empty string default. not used sqlite3. 'options': { "init_command": "set storage_engine=innodb", } } } # local time zone installation. choices can found here: # http://en.wikipedia.org/wiki/list_of_tz_zones_by_name # although not choices may available on operating systems. # if running in windows environment must set same # system time zone. time_zone = 'asia/calcutta' # language code installation. choices can found here: # http://www.i18nguy.com/unicode/language-identifiers.html language_code = 'en-us' site_id = 1 # if set false, django make optimizations not # load internationalization machinery. use_i18n = true # absolute path directory holds media. # example: "/home/media/media.lawrence.com/" #media_root = os.path.join(settings_file_folder,'static') media_root = '/static' static_path = '/static' upload_dir = '/users/iceman/documents/gototest/qbank/static/uploads' site_name = 'demo.com' site_url = 'http://alphadev.demo.com' auth_profile_module = 'core.userprofile' login_redirect_url = '/students/login/' # url handles media served media_root. make sure use # trailing slash if there path component (optional in other cases). # examples: "http://media.lawrence.com", "http://example.com/media/" media_url = '' #static_root = '/users/iceman/documents/gototest/qbank/static' # url prefix admin media -- css, javascript , images. make sure use # trailing slash. # examples: "http://foo.com/media/", "/media/". admin_media_prefix = '/media/' # make unique, , don't share anybody. secret_key = ' hidden ' # list of callables know how import templates various sources. template_loaders = ( # 'django.template.loaders.filesystem.load_template_source', # 'django.template.loaders.app_directories.load_template_source', 'django.template.loaders.filesystem.loader', 'django.template.loaders.app_directories.loader', ) middleware_classes = ( 'django.middleware.gzip.gzipmiddleware', #'utils.xhtmlmortifiermiddleware', 'django.middleware.common.commonmiddleware', 'django.contrib.flatpages.middleware.flatpagefallbackmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', ) session_engine = 'django.contrib.sessions.backends.cached_db' #simplcache_backend = 'memcached://127.0.0.1:11211/' root_urlconf = 'urls' template_dirs = ( settings_file_folder.joinpath("../templates"), # put strings here, "/home/html/django_templates" or "c:/www/django/templates". # use forward slashes, on windows. # don't forget use absolute paths, not relative paths. ) template_loaders = ( #'django.template.loaders.filesystem.load_template_source', #'django.template.loaders.app_directories.load_template_source', 'django.template.loaders.filesystem.loader', 'django.template.loaders.app_directories.loader', ) authentication_backends = ( 'accounts.backends.emailorusernamemodelbackend', 'django.contrib.auth.backends.modelbackend' ) installed_apps = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.admin', 'django.contrib.admindocs', 'django.contrib.sites', 'django.contrib.flatpages', 'core', 'tinymce', 'filebrowser', 'tagging', 'tagging_autocomplete', 'django_extensions', 'registration', 'questionmanager', 'corporate', ) admin_hash_secret = " " recaptcha_public_key = " " recaptcha_private_key = " " serialization_modules = { 'modeljson' : 'wadofstuff.django.serializers.json' } solr_root = "http://dev.demo.com:8080/questionsolr" template_context_processors = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.request", "django.core.context_processors.i18n", "utils.context_processor", "qutils.context_processor", ) #'plugins': "table,paste,searchreplace,safari,asciimath,contextmenu", tinymce_js_url = "/static/tinymce/tiny_mce/tiny_mce.js" tinymce_js_root ="/static/tinymce/tiny_mce" tinymce_default_config = { 'plugins': "table,asciimath,gototest,indicime", 'mode' : "textareas", 'theme': "advanced", 'cleanup_on_startup': true, 'custom_undo_redo_levels': 10, 'theme_advanced_buttons1' : "fontselect,fontsizeselect,formatselect,bold,italic,underline,strikethrough,separator,sub,sup,separator,cut,copy,paste,undo,redo", 'theme_advanced_buttons2' : "justifyleft,justifycenter,justifyright,justifyfull,separator,numlist,bullist,outdent,indent,separator,forecolor", 'theme_advanced_buttons3' : "gototest,backcolor,separator,hr,link,unlink,image,table,code,separator,asciimath,asciimathcharmap,indicime", 'theme_advanced_fonts' : "arial=arial,helvetica,sans-serif,courier new=courier new,courier,monospace,georgia=georgia,times new roman,times,serif,tahoma=tahoma,arial,helvetica,sans-serif,times=times new roman,times,serif,verdana=verdana,arial,helvetica,sans-serif", 'theme_advanced_toolbar_location' : "top", 'theme_advanced_toolbar_align' : "left", 'theme_advanced_statusbar_location' : "bottom", 'tab_focus' : ':prev,:next', } #'content_css' : "/static/css/content.css", tinymce_spellchecker = false tinymce_compressor = true force_lowercase_tags = true markitup_filter = ('markdown.markdown', {'safe_mode': true}) markitup_set = 'markitup/sets/markdown' markitup_skin = 'markitup/skins/markitup' markitup_media_url = '/static/' markitup_auto_preview = true jquery_url = '/static/js/jquery-1.3.2.min.js' tagging_autocomplete_js_base_url = "/static" try: local_settings import * except importerror: pass session_expire_at_browser_close = true
when looking images on browser url = http://127.0.0.1:8000/static/site_img/logo.gif
page not found (404) request method: request url: http://127.0.0.1:8000/static/site_img/logo.gif "/users/iceman/documents/gototest/qbank/qbank/static/site_img/logo.gif" not exist
to anwer specific problem, thing staticfiles_dirs key missing.
this appear debug config file, suppose want serve files django built-in developement web server (ie: doing "manage.py runserver 8000")
1. debug=true|false
you must know django should not used serve files in production , refuse so. if have "debug=false", django refuse serve static files default.
you have use server (most people use nginx, or online cloud service, cloudfront this)
for there 2 step process 1. need collect static files 2. set server serve them
when developping not convenient, django staticfiles_dirs you, , serve static files
2. collecting files
a django website made of multiple applications (see "installed_apps" key in config). each 1 of them may declare static files, in different directories in filesystem.
for files served, need them grouped in single local directory, or single remote server, hence "./manage.py collectstatic".
this command scan every directory listed in staticfiles_dirs , every "static" directory in loaded applications, , copy files place want staticfiles_storage , static_root)
3. config keys
# tells django static files staticfiles_dirs = ( os.path.join(os.path.dirname(__file__), '../static/generated'), os.path.join(os.path.dirname(__file__), '../static/fixed'), ) # developpement # tells django build in web server host files ("http://localhost/static") static_url = '/static/' # production, tell django how {% static %} template tags , "./manage collectstatic" behave (collect files single directory, upload them cdn, etc) # staticfiles_storage = 'django.contrib.staticfiles.storage.staticfilesstorage' # production when using default value staticfiles_storage # tell django collect files when run "./manage.py collectstatic". # used if host static files in same machine rest of application static_root = '/var/www/static.mydomain.com/'
Comments
Post a Comment