gpt4 book ai didi

Django 名称错误 : name 'bPath' is not defined

转载 作者:行者123 更新时间:2023-12-04 06:10:29 25 4
gpt4 key购买 nike

我在 Django 1.7 上运行,当我运行 python manage.py migrate 时出现以下错误

      File "/home/ymorin007/workspace/sites/jantiyes.com/src/deeds/migrations/0006_auto_20141204_1631.py", line 9, in <module>
class Migration(migrations.Migration):
File "/home/ymorin007/workspace/sites/jantiyes.com/src/deeds/migrations/0006_auto_20141204_1631.py", line 19, in Migration
field=models.ImageField(storage=django.core.files.storage.FileSystemStorage(location=bPath('/home/ymorin007/workspace/sites/jantiyes.com/src/media')), max_length=255, null=True, upload_to=deeds.models.picture_name, blank=True),
NameError: name 'bPath' is not defined

这是我的事迹/models.py
from jantiyes.settings.base import MEDIA_ROOT

upload_storage = FileSystemStorage(location=MEDIA_ROOT)

def picture_name(self, filename):

ext = filename.split('.')[-1]
deedname = re.sub('[ ]', '-', self.text.lower())
filename = "DEED-%s-%s.%s" % (self.id, deedname, ext)

url = "%s" % filename

return url


class Deed(TimeStampedModel):

picture = models.ImageField(upload_to=picture_name, null=True, blank=True, storage=upload_storage, max_length=255)
text = models.CharField(max_length=500)
when = models.DateField(unique=True)

我的媒体声明:
BASE_DIR = Path(__file__).ancestor(3)
MEDIA_ROOT = BASE_DIR.child("media")

最佳答案

如果没有 jantiyes.settings.base.MEDIA_ROOT 的确切定义,很难说清楚。但我想这是一个不是 deconstructible 的类( bPath )的实例那是一个subclass of unicode .因此迁移作者假设它不需要任何导入,只需 repr结果是 bPath('/home/ymorin007/workspace/sites/jantiyes.com/src/media') 的值.

你有两个选择:

  • 确保 jantiyes.settings.base.MEDIA_ROOT被定义为字符串,因此由迁移编写器正确处理。例如MEDIA_ROOT = '/home/ymorin007/workspace/sites/jantiyes.com/src/media'在您的 jantiyes.settings.base模块文件。
  • 确保 bPath类可通过定义 deconstruct 来解构方法将导入路径返回给自身。
  • 关于Django 名称错误 : name 'bPath' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27303583/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com