У меня очень простой сайт django, но у меня проблемы с отображением изображений, которые я загружаю в админ-панели.
my settings.py
имеет следующие константы:
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/home/jeroen/programming/python/django/sitename/media'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = 'http://127.0.0.1:8000/media/'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'
мой urls.py
выглядит так:
from django.conf.urls.defaults import *
from django.conf import settings
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^sitename/', include('sitename.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
# http://docs.djangoproject.com/en/dev/howto/static-files/
# This method is inefficient and insecure.
# Do not use this in a production setting.
# Use this only for development.
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
)
и мой models.py
выглядит так:
from django.db import models
class Truitje(models.Model):
titel = models.CharField(max_length=50)
beschrijving = models.TextField(max_length=500)
foto = models.ImageField(upload_to='truitjes')
def __unicode__(self):
return self.titel
Я могу успешно загружать изображения в интерфейсе администратора, и они сохраняются в /home/jeroen/programming/python/django/sitename/media/truitjes
. Но когда я, например, захожу на http://127.0.0.1:8000/media/truitjes/DSC00068.JPG
, я получаю сообщение об ошибке: Page not found: /media/truitjes/DSC00068.JPG
. То же самое для http://127.0.0.1:8000/media/truitjes
и `` http://127.0.0.1:8000/media/gives
Permission отклонено: /media/`.