I'm sorry to ask about this
I'm trying to set up log to be able to test my code; Django pass variable into template
and I was following the example in https://docs.djangoproject.com/en/2.1/topics/logging/
Here the code they use
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': r'C:\Users\Sk\Desktop\project\FrounterWeb\FrounterWeb\logs',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
But i run into this problem, copy and paste and answer i get is this;
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\Sk\Desktop\project\FrounterWeb>py runserver_plus
(null): can't open file 'runserver_plus': [Errno 2] No such file or directory
C:\Users\Sk\Desktop\project\FrounterWeb>py manage.py runserver_plus
Traceback (most recent call last):
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 555, in configure
handler = self.configure_handler(handlers[name])
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 728, in configure_handler
result = factory(**kwargs)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 1041, in __init__
StreamHandler.__init__(self, self._open())
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 1070, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Sk\\Desktop\\project\\FrounterWeb\\FrounterWeb\\logs'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\log.py", line 76, in configure_logging
logging_config_func(logging_settings)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 792, in dictConfig
dictConfigClass(config).configure()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 563, in configure
'%r' % name) from e
ValueError: Unable to configure handler 'files'
I believe this problem with the dictionary, so I remove the 'File':{} & 'django':{} dictionary and i receive another problems
the new code:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': r'C:\Users\Sk\Desktop\project\FrounterWeb\FrounterWeb\logs',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
and this is problems;
Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Users\Sk\Desktop\project\FrounterWeb>py runserver_plus
(null): can't open file 'runserver_plus': [Errno 2] No such file or directory
C:\Users\Sk\Desktop\project\FrounterWeb>py manage.py runserver_plus
Traceback (most recent call last):
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 555, in configure
handler = self.configure_handler(handlers[name])
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 728, in configure_handler
result = factory(**kwargs)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 1041, in __init__
StreamHandler.__init__(self, self._open())
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\__init__.py", line 1070, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Sk\\Desktop\\project\\FrounterWeb\\FrounterWeb\\logs'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\log.py", line 76, in configure_logging
logging_config_func(logging_settings)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 792, in dictConfig
dictConfigClass(config).configure()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 563, in configure
'%r' % name) from e
ValueError: Unable to configure handler 'files'
C:\Users\Sk\Desktop\project\FrounterWeb>py manage.py runserver_plus
Traceback (most recent call last):
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 555, in configure
handler = self.configure_handler(handlers[name])
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 688, in configure_handler
config_copy = dict(config) # for restoring in case of error
ValueError: dictionary update sequence element #0 has length 1; 2 is required
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\management\__init__.py", line 357, in execute
django.setup()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\site-packages\django\utils\log.py", line 76, in configure_logging
logging_config_func(logging_settings)
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 792, in dictConfig
dictConfigClass(config).configure()
File "C:\Users\Sk\AppData\Local\Programs\Python\Python37\lib\logging\config.py", line 563, in configure
'%r' % name) from e
ValueError: Unable to configure handler 'class'
This problem means it can read it own library
I'm sorry trouble you, but pls help me, i really don't know what to since is Django is tell is having problem with own build in library(i think)
/path/to/django/debug.logwith an actual, valid path? If not, you will run into these issues. Replace it with a path such asr'C:\Users\Sk\Desktop\django.log'or somewhere else (make sure the directory exists first, and that you have permissions to create files there). The desktop, Documents and Downloads folders are good candidates. - Burhan Khalidsettings.pycalledlogs, then replace/path/to/django/debug.logwith the full path to the directory, for exampler'C:\Users\Sk\Desktop\FrounterWeb\logs\django.log'- Burhan Khalid