2

I am using Django 1.5.4 and I have a project with the following structure:

django_site
    -django_site
    -books # the app
        -media
            -images
                -books
                -authors
        -static
            -images
    -templates

This is the necessary code:

# settings.py
MEDIA_ROOT = '/root/django_site/books/media/'
MEDIA_URL = '/media/'

# models.py
class Book(models.Model):
    image = models.ImageField(upload_to="images/books/")

# urls.py
urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^books/$', 'books.views.get_all_books'),
)

My problem is that, after adding the image via the admin site, if I click on the image link below the upload button a 404 page shows up, complaining the path does not exist.

The request URL is http://127.0.0.1:8000/media/books/media/images/book/out_of_control_1.JPG but in fact I want the result to be /root/django_site/books/media/images/out_of_control_1.JPG.

How do I fix that? Looking forward to your responses.

Claudio
  • 2,191
  • 24
  • 49

1 Answers1

2

Since you seem to use the developpement server, I think your issue is related to this one : Django MEDIA_URL and MEDIA_ROOT

As explained in the answer, you have to set up a specific URL pattern for media handling when debug is set to True.

You can also have a look at the docs regarding this question.

Community
  • 1
  • 1
Agate
  • 3,152
  • 1
  • 19
  • 30