Django - Error importing storages.backends

后端 未结 4 671
名媛妹妹
名媛妹妹 2021-01-12 03:36

I have created a custom storage backend, the file is called storages.py and is placed in an app called core:

from django.conf impor         


        
相关标签:
4条回答
  • 2021-01-12 04:08

    There is a namespace conflict; the storage absolute name clashes with a storage local name. It may be unintuitive, but you can import from module in itself:

    // file my_module/clash.py
    import clash
    print clash.__file__
    

    Now we run python shell in a dir containing a my_module:

    $ python
    >>> import my_module.clash
    my_module.clash.py
    

    In short, your module tries to import a backend from itself.

    You need an absolute import - Trying to import module with the same name as a built-in module causes an import error.

    0 讨论(0)
  • 2021-01-12 04:15

    I had this same issue, but for me it turns out that despite django-storages being installed, boto was not. A simple pip install boto fixed the error in my scenario.

    0 讨论(0)
  • 2021-01-12 04:18

    I had another type of issue that can help others, I used to have another file named storages.py but I deleted that file days ago, and still getting the Exception... the thing is I didn't had deleted the file storages.pyc !

    0 讨论(0)
  • 2021-01-12 04:24

    Typo error. Change:

    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

    TO:

    DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3Boto3Storage'

    0 讨论(0)
提交回复
热议问题