Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8226161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:40:09+00:00 2026-06-07T15:40:09+00:00

All, i am using Django1.4,i have a question regarding accessing the img files,js files

  • 0

All, i am using Django1.4,i have a question regarding accessing the img files,js files etc… I have my files in the directory /opt/lab/labsite/media/img for images and /opt/lab/labsite/media/js for javascript files.What should i change the settings in the setting files such that the below html works..I am using django server to run the code

My code is currently located in /opt/lab/labsite/settings.py and other modules lies in /opt/lab/labsite/………

 <img src="/media/img/logo.jpg" alt="logo" /> 

Below are the settings in the settings.py file

 # Absolute filesystem path to the directory that will hold user-uploaded files.
 # Example: "/home/media/media.lawrence.com/media/"
 MEDIA_ROOT = '/opt/lab/labsite/media/'

 # URL that handles the media served from MEDIA_ROOT. Make sure to use a
 # trailing slash.
 # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
 MEDIA_URL = ''

 # Absolute path to the directory static files should be collected to.
 # Don't put anything in this directory yourself; store your static files
 # in apps' "static/" subdirectories and in STATICFILES_DIRS.
 # Example: "/home/media/media.lawrence.com/static/"
 STATIC_ROOT = ''

 # URL prefix for static files.
 # Example: "http://media.lawrence.com/static/"
 STATIC_URL = '/opt/lab/labsite/media/'

Changes

  MEDIA_ROOT = '/opt/lab/labsite/media/'

  MEDIA_URL = '/media/'

  STATIC_ROOT = '/opt/lab/labsite/static/'

  STATIC_URL = '/static/'

  STATICFILES_DIRS = (
  )

  # List of finder classes that know how to find static files in
  # various locations.
  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',
  )

  ROOT_URLCONF = 'labsite.urls'

  # Python dotted path to the WSGI application used by Django's runserver.
  WSGI_APPLICATION = 'labssite.wsgi.application'

  TEMPLATE_DIRS = (
      # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
      # Always use forward slashes, even on Windows.
      # Don't forget to use absolute paths, not relative paths.
     '/opt/lab/labsite/templates'
  )

  INSTALLED_APPS = (
      'django.contrib.auth',
      'django.contrib.admin',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.sites',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'home',
      # Uncomment the next line to enable admin documentation:
      # 'django.contrib.admindocs',
  )

  # A sample logging configuration. The only tangible logging
  # performed by this configuration is to send an email to
  # the site admins on every HTTP 500 error when DEBUG=False.
  # See http://docs.djangoproject.com/en/dev/topics/logging for
  # more details on how to customize your logging configuration.

  TEMPLATE_CONTEXT_PROCESSORS = (
     'django.core.context_processors.static',
     'django.contrib.auth.context_processors.auth'
  )

HTML:

 <img src="{{ STATIC_URL }}img/hi.png" alt="Hi!" />
 <img src="/static/img/hi.png" alt="Hi!" />
 <img src="/media/img/hi.png" alt="Hi!" />
 <img alt="Hi!" src="/opt/ilabs/ilabs_site/media/img/hi.png">
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:40:11+00:00Added an answer on June 7, 2026 at 3:40 pm

    STATIC_URL you have set doesn’t look good. I think that should be STATIC_ROOT.

    You should set (for example) MEDIA_URL='/media/' and STATIC_URL='/static/' and I hope you have also enabled static file serving in urls.py

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of conceptual questions: regarding serving static files (media) in Django
We have a large number of programmers on different platforms all using CVS. We
Hi all im using a sqlite helper class, but i have a little problem
Imagine situation: I have view directory with tons of different views. all views have
Say I have two tables (I am using Django, but this question is mostly
I have a simple question. using the example from django above. How can i
I realize this is more of a server question (since all media requests bypass
Argh. Hey all, i have a muy simple django question: And argh, i'm sorry,
I see some frameworks like Django using unicode all over the place so it
I'm using apache+mod_wsgi for django. And all css/js/images are served through nginx . For

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.