Вопрос по – изображения из медиа файла не будут отображаться в шаблоне django

8

Error: User Rate Limit ExceededtryingError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
def location(f):
    return os.path.join(ROOT_DIR, f)
MEDIA_URL = 'http://127.0.0.1:8000/media/'
MEDIA_ROOT = location('media/')

Error: User Rate Limit Exceeded

class Image(models.Model):
    image = models.ImageField(upload_to = 'images/')

Error: User Rate Limit Exceeded

from imageupload.settings import MEDIA_ROOT, MEDIA_URL

def main(request):
    imgs = Image.objects.all()
    return render_to_response('index.html', {'images': imgs, 'media_root': MEDIA_ROOT, 'media_url': MEDIA_URL})

Error: User Rate Limit Exceeded

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

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

<!DOCTYPE html>
<html>
    <img src="<correct path to project>/media/images/photo_1.JPG" />

    {% for img in images %}
    <img src="{{ media_root }}{{ img.image.name }}" />
    <img src="{{ media_url }}{{ img.image.name }}" />
    <img src="{{ img.image.url }}" />
    {% endfor %}
</html>

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

<!DOCTYPE html>
<html>
    <img src="<correct path to project>/media/images/photo_1.JPG" />    
    <img src="<correct path to project>/media/images/photo_1.JPG" />    
    <img src="http://127.0.0.1:8000/media/images/photo_1.JPG" />
    <img src="http://127.0.0.1:8000/media/images/photo_1.JPG" />
</html>

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Ваш Ответ

2   ответа
2

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(SITE_ROOT, 'static')
MEDIA_URL = '/static/'
STATIC_ROOT = os.path.join(SITE_ROOT, 'statics')
STATIC_URL = '/statics/'

Error: User Rate Limit Exceeded

# somebody import this from settings
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))  
urlpatterns += patterns('', 
    url(r'^static/(?P<path>.*)$','django.views.static.serve',
        {'document_root': os.path.join(SITE_ROOT, 'static')})
)

Error: User Rate Limit Exceeded

<img src="{{ MEDIA_URL }}img/content_top_edit_form.png">

Error: User Rate Limit ExceededimgError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<img src="/static/img/content_top_edit_form.png">
Error: User Rate Limit Exceeded Ben
20

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

MEDIA_URL = '/media/'

NOT

MEDIA_URL = 'http://127.0.0.1:8000/media/' 

Error: User Rate Limit Exceeded#'http://127.0.0.1:8000/media/'Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

<img src="/media/images/photo_1.JPG" />

Error: User Rate Limit Exceeded

static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Error: User Rate Limit Exceeded

Похожие вопросы