How do I use CSS in Django?

Viewed 96492

I am creating my application using Django, and am wondering how I can make Django use my CSS file? What settings do I need to do to make Django see the css file?

NB: On a local machine

6 Answers

More generally stated, you're asking how to serve a static file from Django. If you are running under Apache, you should read http://docs.djangoproject.com/en/dev/howto/deployment/modpython/

If you are running the development server (say, on your laptop), read http://docs.djangoproject.com/en/dev/howto/static-files/

Do note the big, fat disclaimer regarding the Django development server:

  • Using this server is inefficient and insecure.
  • Do not use this in a production setting.
  • Use this only for development.

What settings do i need to do to make Django see the css file?

None.

Make sure your template includes the CSS file (as standard HTML does) and put the CSS file on the media server.

To clarify: With Django it is highly recommended that you serve all your media (everything that isn't dynamic html) from a different server instance. How you implement that is completely up to you but most people create a subdomain.

Related