0

I'm running on Django 1.7.4.

# base.py
PRIVATE_FOLDER_ROOT = str(PROJECT_DIR.child('web_private'))
# tested: PRIVATE_FOLDER_ROOT = PROJECT_DIR.child('web_private')
# tested: PRIVATE_FOLDER_ROOT = '/var/www/project/project/web_private'

# models.py
from django.conf import settings

@python_2_unicode_compatible
class MessageFile(models.Model):
    """
    """
    fs_private_folder = FileSystemStorage(location=settings.PRIVATE_FOLDER_ROOT)

    message = models.ForeignKey(Message)
    file = models.FileField('file', storage=fs_private_folder, upload_to=get_upload_path_message_file)

when I run

./manage.py migrate <my_app> --settings=myapp.settings.local

I get the following error

NameError: name 'bPath' is not defined

Checking the 0001_initial.py I see that bPath is not imported or defined.

    fields=[
        ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
        ('file', models.FileField(upload_to=apps.admin_messages.models.get_upload_path_message_file, storage=django.core.files.storage.FileSystemStorage(location=bPath('/var/www/project/project/web_private')), verbose_name=b'file')),
        ('message', models.ForeignKey(to='admin_messages.Message')),
    ],

This SO question is linked to mine, but the proposed solution doesn't work.

Thanks,

D

Community
  • 1
  • 1
Daviddd
  • 761
  • 2
  • 12
  • 37
  • @Selcuk Thanks it was the solution. Please could you remove the comment and add the answer. I spent hours on this issue, I did't think about unicode cast rather than string.... – Daviddd Mar 02 '15 at 08:18

1 Answers1

1

It looks like makemigrations automatically adds a "b" in front of string literals to mark them as byte strings in Python 3.

It may help if you change the cast from str to unicode, ie:

PRIVATE_FOLDER_ROOT = unicode(PROJECT_DIR.child('web_private'))
Selcuk
  • 57,004
  • 12
  • 102
  • 110