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

  • Home
  • SEARCH
  • 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 7857925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:11:46+00:00 2026-06-02T21:11:46+00:00

I just downloaded the latest Django version (1.4.1), and I can’t figure out how

  • 0

I just downloaded the latest Django version (1.4.1), and I can’t figure out how to serve css files when developing locally using runserver. I’ve read the relevant Django docs on static files and many, many questions & answers here… sounds like it’s supposed to be more or less automatic, but it’s not working for me.

I’m working on the polls app from the tutorial.

404 from the log

[27/Apr/2012 01:04:09] "GET /polls/ HTTP/1.1" 200 210
[27/Apr/2012 01:04:09] "GET /polls/css/styles.css HTTP/1.1" 404 2596 

Directory structure

mysite
|-- manage.py
|-- mysite
    |-- __init__.py
    |-- settings.py
    |-- urls.py
    |-- wsgi.py
|-- polls
    |-- __init__.py
    |-- models.py
    |-- tests.py
    |-- views.py
    |-- static
        |-- css
            |-- styles.css
|-- templates
    |-- polls
        |-- index.html

index.html

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/styles.css">

settings.py

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
'django.core.context_processors.static',
)

^^^ I didn’t have the TEMPLATE_CONTEXT_PROCESSORS variable in settings.py when I started the project and had to add it manually – should I be worried about that?

STATICFILES_DIRS is empty, because the css file is in a directory named static within the polls app, which is where Django looks for it automatically – right?

I also have django.contrib.staticfiles in my INSTALLED_APPS.

urls.py

I saw in the docs that this solution works for local development servers other than runserver – sounds like it shouldn’t be necessary otherwise, right? (I currently have it commented out.)

EDIT: I uncommented these lines, but did not see a change – still getting the same 404 on the css file

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()

Do I have my directory structure set up wrong? Am I missing necessary settings in settings.py? Any help would be very much appreciated! Thanks!


EDIT:

I took Mark’s suggestion and read up on RequestContext. Changing my view from:

return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})

to

from django.template import RequestContext
...
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list}, context_instance=RequestContext(request))

got the /static/ url to register:

[27/Apr/2012 13:56:55] "GET /static/css/styles.css HTTP/1.1" 200 19

This fixes the problem.

  • 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-02T21:11:47+00:00Added an answer on June 2, 2026 at 9:11 pm

    In order to use STATIC_URL in the template you need to be sure you are using a RequestContext along with adding 'django.core.context_processors.static' to TEMPLATE_CONTEXT_PROCESSORS. This is done for you if you are using the render shortcut. If you are not using a RequestContext then you can use the {% get_static_prefix %} template tag from the staticfiles template tag library. This is detailed in the docs here: https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#other-helpers

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

Sidebar

Related Questions

I just downloaded the latest version of Netbeans - 6.9.1. I've been using 6.8
I just downloaded the latest version of SQL Express 2012 but I cannot connect
I just downloaded the latest version of Opera. Is there a way to make
I've just installed the latest version of Django (1.4.1) on Ubuntu 12.04. The new
I just downloaded the latest version of SmartMusic (http://www.smartmusic.com) and tried running it for
I just downloaded the latest version of AFNetworking from github . I drag the
I'm trying to use skipfish on ubuntu latest version that I just downloaded. I'm
I am trying to install Django 1.0, I can install latest version of Django
I just downloaded the latest Python IDLE 3.2 for Windows 7 (64-bit). I can
I have a Mac running Lion and I just downloaded latest version of apache.

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.