简体   繁体   English

Django图像显示

[英]Django Images Display

Ok, now I know how to display images on ONE /myurl/ in Django as a list (YEAH!) 好的,现在我知道如何在Django中的一个/ myurl /上以列表形式显示图像了(YEAH!)

But how can I display ONE Image per url with a button to click to the next image etc. 但是如何显示每个URL的一个图像,并带有按钮以单击到下一个图像等。

So basically I would want to come to the first /urlstart/: 所以基本上我想来第一个/ urlstart /:

text and a next button. 文字和下一步按钮。

brings user to eg /urlstart/1 带用户到例如/ urlstart / 1

There the first image of a List is displayed and below that a button. 在那里显示列表的第一张图片,并在其下方显示一个按钮。

That brings user to /urlstart/2 将用户带到/ urlstart / 2

Here the next image of a list is displayed. 在此显示列表的下一个图像。

etc. 等等

How does the url.py regex part have to look like so this is possible? url.py regex部分的外观如何,这样才有可能? How does the view has to be tweaked to get 1 List of Images but multiple urls? 如何调整视图以获取1个具有多个URL的图像列表?

And finally if anybody has implemented this with a down loadable and installable module/library, like eg photologue (which unfortunately did not work for me) or any better idea than that I would be really happy to get some insights on how to make this fast and efficient. 最后,如果有人使用可下载和可安装的模块/库来实现此目的,例如photologue(不幸的是,它对我不起作用)或任何比这更好的主意,那么我将非常高兴获得关于如何快速实现这一点的见解。和高效。

Thanks so much to everybody who takes the time to answer! 非常感谢所有花时间回答的人!

URL regex could look something like this: URL正则表达式可能如下所示:

url(r'^urlstart/(?P<image_id>\d*)/?$', 'urlstart', name='urlstart')

View code could look something like this: 查看代码可能如下所示:

def urlstart(request, image_id=0):
  if image_id == 0:
    image = None
  else:
    image = get_object_or_404(Image, image_id)
  next_image = image_id + 1

  return render_to_response('template.html', locals(), context_instance=RequestContext(request)

Template code: 模板代码:

{% if image %}
  <img src={{ image.url }}>
  <a href="/urlstart/{{ next_image }}">Next</a>
{% else %}
  Put your text here.  See first image by clicking <a href="/urlstart/1">here</a>
{% endif %}

Obviously this is simplified. 显然,这是简化的。 For example, you may want to check to see if there is an image to come next. 例如,您可能要检查下一个图像。

Hope this helps. 希望这可以帮助。

Take a look at Pagination which will provide you with Next/Previous links, etc. 看一下分页 ,它将为您提供下一个/上一个链接等。

Also, it would probably be a good idea to use permalinks and pass the next/previous image in from the view instead of hard-coding the URL into the template. 同样,使用永久链接并从视图中传递下一个/上一个图像,而不是将URL硬编码到模板中,可能是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM