Introduction
This article is focusing about how to solve an error message appear on executing a Django-based framework. The error message itself appears in the title of this article. The error in general exist as follows :
The STATICFILES_DIRS setting is not a tuple or list. HINT: Perhaps you forgot a trailing comma?
Specifically, upon running ‘python manage.py runserver’ to run an internal server, the following error message appear :
(env) C:\programming\python\myproject>python manage.py runserver Watching for file changes with StatReloader Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "C:\Python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "C:\Python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:\programming\python\env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "C:\programming\python\env\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "C:\programming\python\env\lib\site-packages\django\core\management\base.py", line 469, in check raise SystemCheckError(msg) django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues: ERRORS: ?: (staticfiles.E001) The STATICFILES_DIRS setting is not a tuple or list. HINT: Perhaps you forgot a trailing comma? System check identified 1 issue (0 silenced).
Solution
Actually, STATICFILES_DIRS is a constant name exist in ‘settings.py’ file. It is a configuration file for the Django-based web project. So, before getting in into a more deep for the solution, first of all, the following is the actual snippet configuration code exist in the ‘settings.py’ file containing that constant part. The following is the content :
STATICFILES_DIRS = ( os.path.join(BASE_DIR, "myproject", "site_static") )
The error message above is already hinting the solution. The first hint is informing that the STATICFILES_DIRS is not considered as a tuple or list. That is weird considering it is actually a form of a tuple. The following is the actual snippet code configuration of it :
Since the constant’s assignment starts and ends with normal bracket, it is a collection with the tuple type. Since the tuple has only one element, it must end with a comma. Actually what makes a tuple with a single element is considered as a tuple is the comma itself. So, to solve the problem, just add the comma in the end of the first element of the STATICFILES_DIRS constant tuple as follows :
STATICFILES_DIRS = ( os.path.join(BASE_DIR, "myproject", "site_static"), )
After successfully modifying the snippet code configuration above, just run the Django-based project again once more. If there are no other error, it will run normally.