APÍ django-storages dropbox error url pattern

1

I'm using the following API:

link

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

The lib 'storages' in INSTALLED_APPS and the three dropbox connection variables:

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 / media / folder of the project and dropbox, keeping the image in production, having the App created and configured to be app_folder. / p>

If I remove the three dropbox configuration variables and try to modify or add an image by django admin it is possible, however, 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]+(/.*)?)'

It also gives error in dropbox.py of lib:

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, ie 'C: / media / products / ..'.

How to solve this?

    
asked by anonymous 24.11.2018 / 15:56

1 answer

0

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

  

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

As I can not reproduce your error easily, I'll give you some security tips:

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

  • Check at the time you are uploading the files to the desired location.

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

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

    This setting directs 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 run python manage.py collectstatic and make sure your static files are being imported into the dropbox. Keep in mind that when running collectstatics all your static files will have to go to the path defined in your STATIC_ROOT . Having reached this goal you should be fine as django-storages should take care of serving these files.

24.11.2018 / 23:13