Django NameError: name 'bPath' not defined

I run Django 1.7, and when I run python manage.py migrate, I get the following error

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 

This is my business /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) 

My Media Ad:

 BASE_DIR = Path(__file__).ancestor(3) MEDIA_ROOT = BASE_DIR.child("media") 
+6
source share
2 answers

It's hard to say without a precise definition of jantiyes.settings.base.MEDIA_ROOT , but I assume that it is an instance of a class ( bPath ) that is not deconstructive , and it is a subclass of unicode . Therefore, the author of the migration assumes that he does not need to import and simply repr value, which turns out to be bPath('/home/ymorin007/workspace/sites/jantiyes.com/src/media') .

You have two options:

  • Ensure that jantiyes.settings.base.MEDIA_ROOT is defined as a string and thus is handled correctly by the migration author. e.g. MEDIA_ROOT = '/home/ymorin007/workspace/sites/jantiyes.com/src/media' in your jantiyes.settings.base module jantiyes.settings.base .
  • Ensure that the bPath class is non-deformable by defining a deconstruct method that returns the import path to itself.
+7
source

Where is MEDIA_ROOT indicated? I assume that it is defined in your settings file, in which case you will most likely need

 from django.conf import settings upload_storage = FileSystemStorage(location=settings.MEDIA_ROOT) 
+1
source

Source: https://habr.com/ru/post/979142/


All Articles