Django图像显示 [英] Django Images Display

查看:104
本文介绍了Django图像显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,现在我知道如何在一个/ myurl / Django中显示图像作为列表(YEAH!)



但是如何显示每个URL的ONE图像用一个按钮点击下一张图片等。



所以基本上我想要来到第一个/ urlstart /:



文本和下一个按钮。



将用户带到/ urlstart / 1



列表的第一张图像显示在下方,显示一个按钮。



将用户带到/ urlstart / 2



此处显示列表的下一张图像。





url.py正则表达式部分如何看起来像这样,这是可能的?
如何将视图调整为获得1个图像列表,但需要多个URL?



最后如果有人使用可下载和可安装的模块/库,例如photologue(不幸的是不适合我)或任何更好的想法,我会很高兴得到一些见解如何使这个快速和高效。



非常感谢所有花时间回复的人!

解决方案

p> URL regex可能看起来像这样:

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

查看代码可以看如下所示:

  def urlstart(request,image_id = 0):
如果image_id == 0:
image =无
else:
image = get_object_or_404(Image,image_id)
next_image = image_id + 1

返回render_to_response('template.html',本地人(),context_instance = RequestContext(request)

模板代码:

  {%if image%} 
< img src = {{image.url}}>
< a href =/ urlstart / {{next_image}}> Next< / a>
{%else%}
将您的文字放在这里。点击< a href =/ urlstart / 1> ;这里< / a>
{% endif%}

显然这是简化的。例如,您可能需要查看下一张图像是否存在。



希望这有帮助。


Ok, now I know how to display images on ONE /myurl/ in Django as a list (YEAH!)

But how can I display ONE Image per url with a button to click to the next image etc.

So basically I would want to come to the first /urlstart/:

text and a next button.

brings user to e.g. /urlstart/1

There the first image of a List is displayed and below that a button.

That brings user to /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? How does the view has to be tweaked to get 1 List of Images but multiple urls?

And finally if anybody has implemented this with a down loadable and installable module/library, like e.g. 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.

Thanks so much to everybody who takes the time to answer!

解决方案

URL regex could look something like this:

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.

这篇关于Django图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆