我最近创建了博客,所有精美的ecxept图片都没有在主要博客页面中显示
当我打开特定帖子时,图片可见 pictures are shown
当我进入主要博客页面时,图片消失了 no pictures
使用WYSIWYG编辑器froala_editor在管理员中添加图片。
我在下面用来显示博客视图 blog.py
{% extends "personal/header.html" %}
{% block content %}
{% for post in object_list %}
<h5>{{ post.date|date:"Y-m-d" }}<a href="{{post.id}}"> <b> {{ post.title }}</b></a></h5>
<!--<img src="{{ post.img.url }}" class="img-responsive" >-->
{{ post.body|safe|linebreaks|truncatechars:400 }}
{% endfor %}
{% endblock %}
我很感激回复
答案 0 :(得分:2)
替换
<!--<img src="{{ post.img.url }}" class="img-responsive" >-->
用
<img src="{{ post.img.url }}" class="img-responsive" >
答案 1 :(得分:0)
@Sanca Kembang
models.py
'django.db import models
from django_markdown.models import MarkdownField
#dodany model aby mozna bylo dodac kategorie#
class Category(models.Model):
name = models.CharField('Nazwa Kategorii', max_length=100)
slug = models.SlugField('Odnosnik', unique=True, max_length=100)
#icon = models.ImageField('Ikonka Kategorii', upload_to='icons', blank=True#)
class Meta:
verbose_name = "Kategoria"
verbose_name_plural = "Kategoria"
def __unicode__(self):
return self.name
#-----------------------------------------------------#
#Froala
from django.db import models
from froala_editor.fields import FroalaField
class Post(models.Model):
body = FroalaField()
title = models.CharField(max_length = 140)
#body = MarkdownField()
date = models.DateTimeField()
category = models.ManyToManyField(Category, verbose_name='Kategoria')
#img = models.ImageField(upload_to='images', default='DEFAULT VALUE')
def __str__(self):
return self.title' views.py 'from django.shortcuts import render
&#39;这就是我所拥有的
views.py
from django.shortcuts import render
# Create your views here.
@ Riccardo Leschiutta
添加开头这条线没有评论,因为我认为它会有所帮助 - 但是没有,我把它留下了评论
<!--<img src="{{ post.img.url }}" class="img-responsive" >-->