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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:24:01+00:00 2026-05-29T09:24:01+00:00

I’m new to Django, and am trying to set up a really simple Django

  • 0

I’m new to Django, and am trying to set up a really simple Django app.

Now, I’m up to chapter 5 in the Django online book : http://www.djangobook.com/en/2.0/chapter05/

All I want to do now, before I start trying databases, is to add in some simple CS and J to the app as is.

So the question is, how do I do this? I only have one app, and I only want a main.css in a css folder, and a main.js in a js folder.

I checked out the https://docs.djangoproject.com/en/1.3/howto/static-files/#staticfiles-in-templates page, but after reading and reading, there didn’t seem to be a whole lot to work with in terms of examples.

How do I import the stylesheets/css (is there a helper like CakePHP?), where do I put the CSS and JS files, and do I need to configure the static thingy?

UPDATE: the link : Render CSS in Django does not help much. Mainly in that it didn’t work for me, but also I especially don’t like the “if debug” part. What happens when I move to prod? Why would I have my media folder defined differently for prod and local dev anyway? Shouldn’t it be relative, or even in the same spot?

  • 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-29T09:24:02+00:00Added an answer on May 29, 2026 at 9:24 am

    If you follow django’s guidelines, you can simplify your life greatly.

    In your sample code, inside your application directory, create a folder called static. Inside this folder, place your css files.

    Example:

    $ django-admin.py startproject myproject
    $ cd myproject
    myproject$ python manage.py startapp myapp
    myproject$ mkdir myapp/static
    myproject$ cd myapp/static
    myproject/myapp/static$ nano style.css
    

    In your templates:

    <link rel="stylesheet" href="{{ STATIC_URL }}style.css" />

    Make sure you add myapp to the INSTALLED_APPS list in settings.py. Now when you use the built-in development server, your style sheet will be rendered correctly.

    Django searches for a static directory inside installed applications by default, and with current versions of django, static files are enabled by default.


    The Django example has the path my_app/static/my_app/myimage.jpg which
    is a little confusing if your app and project have the same name.

    This is recommended because when you run collectstatic to gather all your static files, files with the same name will be overwritten. If you have a file called myimage.jpg in another application, it will be overwritten. Giving the application name inside the static directory will prevent this, because the exact directory structure will be replicated inside your STATIC_ROOT directory.

    A simple example to illustrate the point. If you have a django project with two apps, like this:

    .
    ├── assets
    ├── manage.py
    ├── myapp
    │   ├── __init__.py
    │   ├── models.py
    │   ├── static
    │   │   └── myapp
    │   │       └── test.txt
    │   ├── tests.py
    │   └── views.py
    ├── myproj
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── settings.py
    │   ├── settings.pyc
    │   ├── urls.py
    │   └── wsgi.py
    └── otherapp
        ├── __init__.py
        ├── models.py
        ├── static
        │   └── otherapp
        │       └── test.txt
        ├── tests.py
        └── views.py
    

    assets is your STATIC_ROOT. Now when you run collectstatic:

    .
    ├── assets
    │   ├── myapp
    │   │   └── test.txt
    │   └── otherapp
    │       └── test.txt
    ├── manage.py
    ├── myapp
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── models.py
    │   ├── static
    │   │   └── myapp
    │   │       └── test.txt
    │   ├── tests.py
    │   └── views.py
    ├── myproj
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── settings.py
    │   ├── settings.pyc
    │   ├── urls.py
    │   └── wsgi.py
    └── otherapp
        ├── __init__.py
        ├── __init__.pyc
        ├── models.py
        ├── static
        │   └── otherapp
        │       └── test.txt
        ├── tests.py
        └── views.py
    

    You see it is creating the directories as well. In your templates you would now refer to each file with its “namespace” of the app: {{ STATIC_URL }}/myapp/test.txt

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.