Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Django Templates Static Assets

Mirko Xiang Zhao
Mirko Xiang Zhao
17,787 Points

Admin page lost css after including STATICFILES_DIRS = { os.path.join(BASE_DIR, 'assets') } [SOLVED]

After I include the setting STATICFILES_DIRS = { os.path.join(BASE_DIR, 'assets') }

I tried to log in to the Admin page but it just became a plain html construction loosing all the css and throwing an error stating it couldn't find the css files.

If I remove the above lines all works again.

Any help is highly appreciated, I am completing the tutorial on my own machine. Cheers,

Mirko

Chris Komaroff
Chris Komaroff
Courses Plus Student 14,198 Points

Hi, I don't get this problem, admin looks okay, but not sure I understand your issue.

3 Answers

Mirko Xiang Zhao
Mirko Xiang Zhao
17,787 Points

[SOLVED] I just modified that line to include the admin css dir as follows: STATICFILES_DIRS = [ os.path.join(BASE_DIR, "assets"), '/static/admin', ]

not sure if it's not recommended but it appears to work now :)

Daniel Jeffery
Daniel Jeffery
1,572 Points

The issue is that you've used a dictionary instead of a tuple!

As you have noted a list also works, but in Kenneth's example he uses a tuple.

If you think about how a dictionary works, you will see why it didn't get the desired result in this case.

Sameer Zahid
Sameer Zahid
5,967 Points

The actual code in the video is this:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'assets'),
)

Notice that it is a tuple with regular brackets and not curly. Also since it is a tuple, you can't skip the comma at the end, ie. the comma is compulsory and not optional, in fact that is what makes it a tuple.