我有macOS塞拉利昂,我修改了以前的Django项目(项目是在Linux系统上创建的,也许这会调用一些bug)。
我有文件夹static
和文件夹landing
在static
中
当我运行服务器时,它会打印出来:GET /static/landing/img/397x300/03.jpg HTTP/1.1" 404 1691
这是我的带有变量静态的settings
文件-
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
'/Users/milkiweed/Documents/python/django/psy_site/static'
UPD。当我尝试使用python3 manage.py collectstatic
时,我有下一个问题:
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/contrib/staticfiles/management/commands/collectstatic.py" , line 199,in handle
collected = self.collect()
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/contrib/staticfiles/management/commands/collectstatic.py" , line 124,in collect
handler(path, prefixed_path, storage)
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/contrib/staticfiles/management/commands/collectstatic.py" , line 354,in copy_file
if not self.delete_file(path, prefixed_path, source_storage):
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/contrib/staticfiles/management/commands/collectstatic.py" , line 260,in delete_file
if self.storage.exists(prefixed_path):
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/core/files/storage.py", line 392, in exists
return os.path.exists(self.path(name))
File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site- packages/django/contrib/staticfiles/storage.py", line 50, in path
raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
发布于 2017-10-22 16:00:21
在您的开发(DEBUG=True
)环境中,在settings.py
中需要两样东西
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
假设您的static
目录位于顶层的BASE_DIR
中,这就足够了。如果您的static
目录位于其他地方,则相应地调整STATICFILES_DIRS
。
https://stackoverflow.com/questions/46875481
复制相似问题