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 6018085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:13:24+00:00 2026-05-23T03:13:24+00:00

I am using Django 1.3 with built-in static app. My static folder structure is

  • 0

I am using Django 1.3 with built-in static app.

My static folder structure is like this:

static/
    css/
       main.css
       img/
    js/

So I tried to reference images under static/css/img/ folder from CSS like this:

background:url('img/btn_white.gif') repeat-x;

But the images don’e show up. When I inspect elements in Chrome, I found the image path to be http://localhost/mysite/static/css/main.css/img/btn_white.gif/

Which is very wierd since this relative path should have referenced static/css/ folder instead of main.css. So I tried to change path to be url('../img/btn_white.gif'), and it works in Chrome and Firefox but not in IE.

I am pretty sure this problem is related to Django, because in my pure HTML/CSS, this relative path works just fine. I also tried to put css in media folder and the problem is the same.

My settings related to static app:

in settings.py:

STATIC_ROOT = os.path.join(os.path.dirname(__file__),'static').replace('\\','/')
STATIC_URL = 'http://localhost/mysite/static/'

in urls.py:

(r'^static/(?P<path>.*)/$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),

Related question: Is a relative path in a CSS file relative to the CSS file?

  • 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-05-23T03:13:25+00:00Added an answer on May 23, 2026 at 3:13 am

    The problem is caused by your URLconf, specifically the pattern:

    r'^static/(?P<path>.*)/$'
    

    This means that a the URL must end in a forward slash for it to match this pattern. i.e. the following URL will not match: (because it doesn’t have a trailing slash)

    /mysite/static/css/main.css
    

    The weird thing, is that it does work. The reason for this is Django’s APPEND_SLASH setting:

    When set to True, if the request URL does not match any of the patterns in the URLconf and it doesn’t end in a slash, an HTTP redirect is issued to the same URL with a slash appended. Note that the redirect may cause any data submitted in a POST request to be lost.

    So when your browser makes a request to:

    /mysite/static/css/main.css
    

    …Django will fail to match it against any of the URLs, and will issue a redirect to: (because APPEND_SLASH defaults to True)

    mysite/static/css/main.css/
    

    This new request will succeed and your browser will now be able to download the CSS file, however the CSS file’s resource URL now ends with a slash. When your browser processes the CSS rules and comes across:

    background:url('img/btn_white.gif') repeat-x;
    

    It will attempt to join that relative URI to the URI of the CSS resource. e.g.:

    /mysite/static/css/main.css/ + img/btn_white.gif = /mysite/static/css/main.css/img/btn_white.gif
    

    This will fail, so your browser will get a redirect to: (again because of APPEND_SLASH)

    /mysite/static/css/main.css/img/btn_white.gif/
    

    But obviously that too will fail.

    Solutions

    Change your URL pattern to the following: (note the removed trailing / in the pattern)

    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    

    Or use one of the recommended methods:

    from django.conf import settings
    
    if settings.DEBUG:
        urlpatterns += patterns('django.contrib.staticfiles.views',
            url(r'^static/(?P<path>.*)$', 'serve'),
        )
    

    …or:

    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    
    # ... the rest of your URLconf here ...
    
    urlpatterns += staticfiles_urlpatterns()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Django's built in models, how would one create a triple-join between three models.
I'm using Django to write a blog app, and I'm trying to implement a
I'm using django's built-in contrib.auth module and have setup a foreign key relationship to
I develop web applications using Django on Mac OSX 10.6. I use Django's built
I'm considering using Django for a project I'm starting (fyi, a browser-based game) and
I am having problems using django-tagging . I try to follow the documentation but
I'm using Django and Python 2.6, and I want to grow my application using
I'm using django and when users go to www.website.com/ I want to point them
I am currently using Django to construct JSON encoded objects which a retrieved using
Is it possible to have a variable number of fields using django forms? The

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.