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

Logesh Jayaraman
Logesh Jayaraman
445 Points

Static files

I did exactly as mentioned in the course for adding the static files. But i am getting the error as

NameError at / name 'staticfiles_urlPatterns' is not defined Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 1.8.3 Exception Type: NameError Exception Value:
name 'staticfiles_urlPatterns' is not defined

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Did you import it?

from django.contrib.staticfiles.urls import staticfiles_urlpatterns
Logesh Jayaraman
Logesh Jayaraman
445 Points

Thanks Chris. I did do the import. It is the issue with the spaces. But i have another problem in accessing the images,CSS and js files.

I had updated the settings.py as

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

Actual path for images is c:\gt\assets\images Actual path for js is c:\gt\assets\js

when access the http://127.0.0.1:8000, the image and JS path is showing as http://127.0.0.1/home/css/bootstrap.min.css Failed to load resource: the server responded with a status of 404 (Not Found) http://127.0.0.1:8000/images/home/logo1.png Failed to load resource: the server responded with a status of 404 (NOT FOUND)

Which are wrong.

[MOD: edited formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

What is the Django template line used to reference these assets?

Have you tried entering the URL directly into the browser? Try: http://127.0.0.1/static/images/logo1.png, etc.