在我的models.py中(myfile.txt为3gb)
with open('/static/myfile.txt', 'rb') as f:
do something..
但它抱怨
No such file or directory: '/static/myfile.txt'
这是我的settings.py
STATIC_ROOT = 'absolute_dir_to_project/app_name/static/'
STATIC_URL = '/static/'
我错过任何一步了吗?
您应该在绝对路径前加上SETTINGS
STATIC_URL,以便它myfile.txt
在Django中查找:
from django.conf import settings # dont forget to import this guy
with open(settings.STATIC_URL + 'myfile.txt', 'rb') as f:
do something..
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句