Search code examples
pythondjangodjango-grappellidjango-filebrowser

Django-Filebrowser and uploading images


I have Django Grappelli == 2.6.5 with Filebrowser and Tinymce. I use Django ==1.7.5. I have problem with uploading images. Image uploads in the browser, appears in the folder \media\uploads but Filebrowser doesn't see it and throws an error: 'media\uploads\img.jpg' could not be found Here is my settings:

STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
MEDIA_URL = STATIC_URL + "media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/')

In the pyhon shell I did following:

from django.conf import settings 
import filebrowser.settings
filebrowser.settings.MEDIA_ROOT
C:\\mysite\\static\\media
filebrowser.settings.DIRECTORY
uploads/

Why is this happened? How can I set the right upload directory to Django-Filebrowser? I've read documentation and searched for answears in google. But I don't understand how fix it and I'm confused. Can you help me please.


Solution

  • in your projects urls.py:

    from django import views
    ....
    
    
    urlpatterns = [
    
    ...
    
    url(r'^media/(?P<path>.*)$', views.static.serve, {
            'document_root': settings.MEDIA_ROOT})
    ...
    
    ]