How to Solve Error Message django.core.exceptions.ImproperlyConfigured: The LOCALE_PATHS setting must be a list or a tuple.

Posted on

Introduction

This is an article where the error message appear upon executing a Django-based framework application. The error message is available in the title of this article. It appear after editing a file with the name of ‘settings.py’. There are several configuration lines which is triggering the error message. It is the following line :

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale")
)

The complete error appear upon running ‘python manage.py runserver’. It is a command for running internal server for providing a service to respond the application’s access.

(env) C:\programming\python\myproject>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\programming\python\env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\programming\python\env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\programming\python\env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\programming\python\env\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
super().execute(*args, **options)
File "C:\programming\python\env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\programming\python\env\lib\site-packages\django\core\management\commands\runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\programming\python\env\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "C:\programming\python\env\lib\site-packages\django\conf\__init__.py", line 69, in _setup
self._wrapped = Settings(settings_module)
File "C:\programming\python\env\lib\site-packages\django\conf\__init__.py", line 184, in __init__
raise ImproperlyConfigured("The %s setting must be a list or a tuple. " % setting)
django.core.exceptions.ImproperlyConfigured: The LOCALE_PATHS setting must be a list or a tuple.

(env) C:\programming\python\myproject>

Solution

After adding the above snippet configuration lines, the error message appear. Actually, the mistake is very common and it is a simple mistake. As in the above definition of a constant with the name of LOCALE_PATHS, the ‘(‘ and ‘)’ usage actually the type of it. Since the assignment operator is assigning a definition using ‘(‘ and ‘)’, it means it is a list. A list must have a comma at the end of it if there is only one element inside of it. So, change the above snippet configuration in order to solve the problem and make the application running properly. Just add one comma at the end of the element of LOCALE_PATHS. So, the correct change or modification will be exist as follows :

LOCALE_PATHS = (
    os.path.join(BASE_DIR, "locale"),
)

Run the application once more. If there is no more errors exist, the application will running properly.

Leave a Reply