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!

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

getting TemplateSyntaxError: 'staticfiles' is not a registered tag library. [Solved]

urls.py file: from . import views from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [ url(r'^courses/', include(courses.urls)), path('admin/', admin.site.urls), path('', views.hello_world), ]

urlpatterns += staticfiles_urlpatterns()

setting.py file:

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

layout.html file: {% load static from staticfiles %}

<!doctype html> <html lang="en"> <head> <title>{% block title %}{% endblock %}</title> <link rel="stylesheet" type="text/css" href="{% static 'css/layout.css' %}"> </head> <body> <div class="site-container"> {% block content %} {% endblock %} </div> </body> </html>

2 Answers

Ok so i fixed my issue. If you are using pycharm and Django 3.0 and get this error in layout.html change {% load static from staticfiles %} to just {% load static %} If you type everything right it should work