Photologue不显示图像或缩略图

时间:2018-10-11 20:42:11

标签: photologue

我无法获得写真照来显示图像。我在做什么错了?

开发环境

  • django 2.1
  • python 3.5
  • osx,virtual_env,最近点值

settings.py

MEDIA_ROOT = os.path.join(BASE_DIR, 'mst/media/')
MEDIA_URL = "/media/"

网址

urlpatterns += [
    ...
    url(r'^photologue/', include('photologue.urls', namespace='photologue')),
]
模型
from photologue.models import Photo, Gallery

class PhotoExtended(models.Model):
    photo = models.OneToOneField(Photo, on_delete=models.CASCADE, related_name='photo')
    related_model = models.ForeignKey(MyModel, on_delete=models.CASCADE)

    def __str__(self):
        return self.photo.title

class GalleryExtended(models.Model):
    gallery = models.OneToOneField(Gallery, on_delete=models.CASCADE, related_name='gallery')
    related_model = models.ForeignKey(MyModel, on_delete=models.CASCADE)

    def __str__(self):
        return self.gallery.title

基于类的视图

class MyModelList(ListView):
    model = MyModel
    template_name = "pictures.html"

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context['photos'] = PhotoExtended.objects.all()
        context['galleries'] = GalleryExtended.objects.all()
        return context

模板(pic​​tures.html):

{% block content %}
    <ul>
        {% for photoExtended in photos %}
            <li>{{ photoExtended.photo.get_absolute_url }}</li>
            <li>{{ photoExtended.photo.image }}</li>
            <img src="/{{ photoExtended.photo.image }}" alt="{{ p.photo.title }}">
        {% endfor %}
        {% for gallery in galleries %}
          <li></li>
        {% endfor %}

shell响应(每个docs

>>> from PIL import Image
>>>

笔记

我迁移了数据库,并查看了数据库中的数据,一切看起来都正确。




页面效果

照片网址:

单张照片

a single image

照片列表 a list of photos

以及直接访问图像:(ra是照片日志中的名称,而em.jpeg是文件名)

direct access of the image

直接查看我的观点

enter image description here

1 个答案:

答案 0 :(得分:0)

该模板错误/较旧版本已过时。这是photologueExtended类型的图像列表中图像的模板中的正确用法:

{% for photoExtended in photos %}            
    <!-- The link to the photologue template page with the photo and its gallery(s)-->
    <a href="{{ photoExtended.photo.get_absolute_url }}">Link to page</a>
    <!-- The src link to the image thumbnail itself in the media url-->
    <img src="{{ photoExtended.photo.get_thumbnail_url }}" />
    <!-- The src link to the image itself in the media url-->
    <img src="{{ photoExtended.photo.get_display_url }}" />
    <!-- The photologue image's title/description/etc… -->
    {{ photoExtended.photo.title }} <br>
    {{ photoExtended.photo.description }} <br>
{% endfor %}

也:

主项目urls.py中的url catchall不正确,应为:

url(r'^$', indexView, name='indexView'),