Why not show pictures of Django?

0 like 0 dislike
15 views
Do not see the images on my project, the url seems correct, the picture right is pumped out in the media.
Blog - app.
djangoBlog - the main application.
MEDIA_ROOT:
MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Project structure:
65766c4511.jpg
The html code which displays the picture:
{% extends 'base.html' %} {% block content %} {% if post.published_date %} {{ post.published_date }} {% endif %} {% if user.is_authenticated %} {% endif %} {{ post.title }}
Картинка поста

{{ post.text|linebreaksbr }}

{% endblock %}
blogs/urls.py:
from django.conf.urls import url from . import views mapping includes = [ url(r'^$', views.our post_list, name='our post_list'), url(r'^post/(?P\\d+)/$', views.post_detail, name='post_detail'), url(r'^post/new/$', views.post_new, name='post_new'), url(r'^post/(?P\\d+)/edit/$', views.post_edit, name='post_edit'), ]

blogs/view.py:
from django.shortcuts import render, get_object_or_404, redirect from django.utils import timezone from .models import Post from .forms import PostForm def our post_list(request): posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date') return render(request, 'post_list.html', {'posts': posts}) def post_detail(request, pk): post = get_object_or_404(Post, pk=pk) return render(request, 'post_detail.html', {'post': post}) def post_new(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.published_date = timezone.now() post.save() return redirect('post_detail' pk=post.pk) else: form = PostForm() return render(request, 'post_edit.html', {'form': form}) def post_edit(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.published_date = timezone.now() post.save() return redirect('post_detail' pk=post.pk) else: form = PostForm(instance=post) return render(request, 'post_edit.html', {'form': form})

blogs/models.py:
from django.db import models from django.utils import timezone class Post(models.Model): author = models.ForeignKey('auth.User', on_delete=models.CASCADE) title = models.CharField(max_length=200) text = models.TextField() created_date = models.DateTimeField( default=timezone.now) published_date = models.DateTimeField( blank=True, null=True) post_image = models.ImageField(upload_to='post_images/', blank=True, null=True) def publish(self): self.published_date = timezone.now() self.save() def __str__(self): return self.title


Here directly the code on the site:
a20d4c83f1.jpg

Error when you go to the link image:

f52c5dc73e.png

Threw all sorts of data like :)
by | 15 views

1 Answer

0 like 0 dislike
In urls.py not enough settings media

from django.conf import settings from django.conf.urls.static import static mapping includes = [ # ... the rest of your URLconf goes here ... ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,907 users