[Solved]-Adding static() to urlpatterns only work by appending to the list


Well the static function does not return a single url, so you can not add it as a single element to the list. By using +=, you actually append all the elements of the result of the static call to the list.

Recent versions of Python however have special syntax to include an iterable in a list by using the asterisk (*), so it can still be done with:

urlpatterns = [
    # some routes,
    *static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Leave a comment