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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:40:40+00:00 2026-05-26T07:40:40+00:00

I am working on writing a Django app for the first time, so bear

  • 0

I am working on writing a Django app for the first time, so bear with me if I’m a little behind on things.

Here is an excerpt from my settings.py:

STATIC_ROOT = os.getcwd().replace('\\','/') + '/static'

STATIC_URL = '/static_files/'

STATICFILES_DIRS = (
    os.getcwd().replace('\\','/') + '/static'
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

Note: I’m hoping that the os.getcwd()... line works. I am pretty sure it’s not my problem, but please let me know if this is an issue. It’s a placeholder for local dev purposes, so don’t worry about it remaining there when I deploy.

My first issue is that template variables don’t seem to be working.

An excerpt from my main template file:

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL|default:'/static_files/' }}css/base.css" />

I originally just had {{ STATIC_URL }} in there, but that simply returned nothing, so I tried adding |default:'...'. This did successfully generate the given string in the resulting HTML, but still didn’t work, which brings me to my second (and more important, honestly) issue.

I can’t get static files to work at all. I have tried several different methods here. I have tried putting absolute and relative paths (in various combinations) in each of the above STATIC_* variables, I have tried using the equivalent MEDIA_URL vars instead, and I have tried putting the following into my urls.py:

urlpatterns = ('',

    # ...

    (r'^static_files/(?P<path>.*)$', 
        'serve', {
            'document_root': '/path/to/django/dir/static_files/',
            'show_indexes': True 
        }
    ),
)

(I grabbed the above snippet from http://www.arthurkoziel.com/2008/09/02/handling-static-files-django/.)

Now I should note that I will hopefully be eventually serving up static files from a parallel Apache process once initial dev is completed, but I would still really like to know what I’m doing wrong. I haven’t been able to find a decently comprehensive tutorial on static files online or on StackOverflow.

All help is greatly appreciated.

EDIT: In case it is important, I am on Windows 7 using Python 2.7.

  • 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-26T07:40:41+00:00Added an answer on May 26, 2026 at 7:40 am

    One possibility – STATIC_URL won’t be filled out in your templates unless you’re passing in a RequestContext.

    Make sure you have something like this in your views:

    return render_to_response(template, context, context_instance=RequestContext(request))
    

    As of Django 1.3 you can also use the new shortcut:

    return render(request, template, context)
    

    Also, make sure you have ‘django.core.context_processors.static’ in your context processors.


    EDIT: Possible answer to the second problem, try changing

    STATICFILES_DIRS = (
        os.getcwd().replace('\\','/') + '/static'
    )
    

    to

    STATICFILES_DIRS = (
        os.getcwd().replace('\\','/') + '/static',
    )
    

    EDIT 2: More possible fixes

    You can delete STATICFILES_FINDERS. You only have it set to the default, so unless you intend to expand it later on, get rid of it (one less thing to go wrong).

    You can also get rid of the urlpatterns entry. Not necessary.

    Your STATIC_ROOT is probably incorrect. This should be the place where Django will gather all the static files from across your project (including the directories described in STATICFILES_DIRS) when you move to production.

    An example from a typical settings.py of mine:

    PROJECT_DIR = os.path.dirname(__file__)
    
    STATIC_URL = '/static/'
    
    STATICFILES_DIRS = (
        os.path.join(PROJECT_DIR, 'static'),
    )
    
    STATIC_ROOT = '/var/www/myproject_staticfiles/'
    

    That’s it!

    If you want to test whether Django is finding and placing your static files correctly, try running

    python manage.py collectstatic
    

    In my case, that would go through my project directories, find all the static files, then copy them across to ‘/var/www/myproject_staticfiles/’, where I can host them with apache.

    The Django dev server automagically serves static files from within your project folder, so no collect_static is required while in dev. You don’t even need to set STATIC_ROOT until you go into production.

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

Sidebar

Related Questions

I have a little project I am working. I am writing django database to
NEWBIE ALERT! background: For the first time, I am writing a model that needs
I am working writing a regular expression used to validate string in C. Here
I've been working on writing a library in my spare time to familiarize myself
I am currently working on writing strstr from scratch. In my code, I am
I just got done working through the Django tutorials for the second time, and
Using: Ubuntu 11.04 Django 1.3 Python 2.7 Following the tutorial at Writing your first
I'm working on writing a little implementation of RSA to help me study for
I'm working on a large Django app, the vast majority of which requires a
I've been working on writing a BitTorrent client in C in my spare time.

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.