我正在尝试运行我的Python manage.py
服务器并返回错误,但是错误似乎指向了错误的文件,不确定为什么会这样。
当我需要将其指向"Demoproject"
时,它似乎指向的文件是"Slidelytics_site"
。
是否存在可能错误的路径,或者是否有特定的.py
文件包含可以调整的此路径?
有趣的旁注-当我从settings.py文件中删除以下代码时,不会发生此错误。
有趣的旁注-当我从settings.py文件中删除以下代码时,不会发生此错误。
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
# '/var/www/static/',
]
PS
C:\Users\trueb\Desktop\Slidelytics_site> python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03FB7780>
Traceback (most recent call last):
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\contrib\staticfiles\checks.py", line 9, in check_finders
finder_errors = finder.check()
File "C:\Users\trueb\Desktop\demoproject\venv\lib\site-packages\django-2.1.5-py3.7.egg\django\contrib\staticfiles\finders.py", line 82, in check
if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
File "C:\Users\trueb\AppData\Local\Programs\Python\Python37-32\lib\ntpath.py", line 526, in abspath
return normpath(_getfullpathname(path))
TypeError: _getfullpathname: path should be string, bytes or os.PathLike, not tuple
我希望能更好地了解在哪里寻找或进行哪些更改以解决此问题。
答案 0 :(得分:0)
您的STATIC_ROOT
设置似乎是一个元组。如错误消息所述,它应该是字符串,字节或os.PathLike。最可能的原因是流浪逗号,如下所示:
>>> STATIC_ROOT = '/my/static/root', # <- note the trailing comma
>>> type(STATIC_ROOT)
<class 'tuple'>
>>> STATIC_ROOT = '/my/static/root'
>>> type(STATIC_ROOT)
<class 'str'>
如果查看source of this exception,您会发现它在for循环中,该循环遍历STATICFILES_DIR
。默认情况下,此设置为空列表。这就解释了为什么如果删除那些看似无关的设置,错误就会消失。
对于错误的路径,我猜您启用了错误的virtualenv。尝试使用deactivate
命令或直接启动一个新的控制台/ cmd窗口。