0

我无法获得 photologue 来显示图像。我究竟做错了什么?

开发环境

  • django 2.1
  • 蟒蛇3.5
  • osx,virtual_env,最近的点子

设置.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 %}

外壳响应(每个文档

>>> from PIL import Image
>>>

笔记

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




页面效果图

照片记录网址:

单张照片

单个图像

照片列表 照片列表

以及图像的直接访问:(ra是photologue中的名称,但em.jpeg是文件名)

直接访问图像

和我的看法直接:

在此处输入图像描述

4

1 回答 1

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 %}

还:

主项目中的 url catchallurls.py不正确,应该是:

url(r'^$', indexView, name='indexView'),
于 2018-10-12T04:55:44.143 回答