我正在尝试从django应用程序访问静态文件,以访问django应用程序之外的静态文件。 我想将UIUX/static中的文件复制或访问到DjangoRepo/myapp/static。 它看起来像下面
UIUX/
- static
- staticfile...
- templates
- index.html
DjangoRepo/
- myapp
- static
- templates
我的设置文件
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = '/static/'
# trying to access the static file outside of django file
STATICFILES_DIRS = (
#os.path.join(PROJECT_ROOT, 'static/'),
"C:/Users/kevin/workspace/UIUX/static"
)
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
当我运行python manage.py collectstatic
时,我得到了这个
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 188, in handle
collected = self.collect()
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 105, in collect
for path, storage in finder.list(self.ignore_patterns):
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\contrib\staticfiles\finders.py", line 131, in list
for path in utils.get_files(storage, ignore_patterns):
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\contrib\staticfiles\utils.py", line 23, in get_files
directories, files = storage.listdir(location)
File "C:\Users\iact80h\.virtualenvs\lynx-ocr-python-services-6157-7DFxjqs2\lib\site-packages\django\core\files\storage.py", line 315, in listdir
for entry in os.scandir(path):
FileNotFoundError: [WinError 3] 指定されたパスが見つかりません。: 'C:\\Users\\kevin\\workspace\\lynx-ocr-python-services-6157\\C'
甚至可以访问项目外部的静态文件吗
对!!您可能想从Django的官方文档中了解STATICFILES_DIRS
研究以下代码:
STATICFILES_DIRS
必须是list
(或tuple
),而不是str
因此,尝试改变:
致:
相关问题 更多 >
编程相关推荐