这是一个非常初学者的问题。但是我很沮丧。如何在model.py中引用Django设置变量?
NameError: name 'PRIVATE_DIR' is not defined
还尝试了很多其他东西,包括 settings.PRIVATE_DIR
settings.py:
PRIVATE_DIR = '/home/me/django_projects/myproject/storage_dir'
models.py:
# Problem is here.
from django.core.files.storage import FileSystemStorage
fs = FileSystemStorage(location=PRIVATE_DIR)
class Customer(models.Model):
lastName = models.CharField(max_length=20)
firstName = models.CharField(max_length=20)
image = models.ImageField(storage=fs, upload_to='photos', blank=True, null=True)
正确的方法是什么?
from django.conf import settings
- docs.djangoproject.com/en/dev/topics/settings/...