APÍ Django-storages Dropbox url error Pattern

Asked

Viewed 133 times

1

I am using the following API:

https://django-storages.readthedocs.io/en/latest/backends/dropbox.html

I have exactly everything configured, from the lib installed to the settings of Settings.py.

A lib 'storages' in INSTALLED_APPS and the three variables of connection with Dropbox:

DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DROPBOX_OAUTH2_TOKEN = 'meu_token'
DROPBOX_ROOT_PATH = '/media/'

I want the Filefield and Imagefield fields to upload an image or file and save it in the project’s/media/ folder and the Dropbox, keeping the image in production, having the App created and configured to be app_folder.

If I remove the three configuration variables from Dropbox and try to modify or add an image by Django admin is possible, but when I return the variables and try again, the following error appears:

  ValidationError at /admin/catalog/product/6/change/
'C:/media/products/cortina-city.jpg' did not match pattern '(/(.|[\r\n])*|id:.*)|(rev:[0-9a-f]{9,})|(ns:[0-9]+(/.*)?)'

Gives error also in lib Dropbox.py:

C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\storages\backends\dropbox.py in exists
                return bool(self.client.files_get_metadata(self._full_path(name))) ...
        C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\base.py in files_get_metadata
                                       include_property_groups) ...
        C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\files.py in __init__
                self.path = path ...
        C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\files.py in path
            val = self._path_validator.validate(val) ...
        C:\Users\evert\Desktop\Synth\SynthDev\myenv\lib\site-packages\dropbox\stone_validators.py in validate
                                      % (val, self.pattern)) 

I understand that you are not identifying the url get pattern. I imagine that C: should not go together in the string and is going, i.e., 'C:/media/products/..".

How to solve this?

  • Everton , like this your file urls.py ?

  • I have the configuration: if Settings.DEBUG: urlpatterns += Static(Settings.MEDIA_URL, document_root=Settings.MEDIA_ROT)

1 answer

0


Personally I think dealing with the static files in the production environment is one of the most complicated things. As the own documentation says:

Of course, like all deployment tasks, the problems are in the details. Each production configuration will be a little different, so you will need to adapt the basic scheme to suit your needs.

As I won’t be able to reproduce your error easily, I give you some safety tips:

  • Check where your configuration variables like STATIC and MEDIA are pointing. Tabs should be pointing to the root path of your project.

  • Check the moment you are going up the files which the desired location.

    FileField(upload_to='media/', null=True, blank=True) #exemplo
    
  • Check your urls.py. You mentioned that you are using:

     if settings.DEBUG: 
         urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    

    This arrow setting your 'Static' to be a combination of your STATIC_URL and STATIC_ROOT so make sure the two are also properly configured in your Settings.py

    Use:

     url(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),
    

    Although not recommended, it will also help you map your files static for your routes.

  • Finally turn python manage.py collectstatic and make sure your static files are being properly imported into Dropbox. Keep in mind that when you run collectstatics all your static files will have to go to the path set in your STATIC_ROOT. Having reached that goal you should be fine because the Django-storages should be responsible for serving these archives.

  • Otávio, thanks for the excellent tips, however, I have everything configured and apparently is ok. &#xA;&#xA;No meu settings.py: MEDIA_URL = '/media/'; STATIC_URL = '/static/'; MEDIA_ROOT = os.path.join(BASE_DIR, 'media'); STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

  • The image attribute looks like this: image = models.Imagefield('Image', upload_to='products', Blank=True, null=True). This way a products folder will be created inside media. How it works normally local.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.