Django 缩略图,简单
我有一个包含静态内容的文件夹,site_media。它是使用 django.views.static.serve 提供的
#settings.py:
STATIC_DOC_ROOT = 'site_media/'
,
#urls.py:
urlpatterns = patterns('',
(...)
url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT, 'show_indexes':True})
)
现在,我只想在我的网站上显示这些图片的较小版本。我希望有一个带有模板标签的应用程序可以轻松做到这一点。
我梦想着这样的事情: {% img "/site_media/foo.png" "100x100" %}
这会在 site_media 中的某个位置创建一个调整大小的图片,然后返回该图片的 url,可能是“site_media/resized/foo_100x100.png”。
我一直在研究 Sorl-Thumbnail,但老实说我不太明白它是如何运作的。抱歉,如果我错过了,但在我看来,他们似乎从未解释过从 http 请求到响应的流程。我也不确定 Sorl 是否适合我的问题。
I have a folder with static content, site_media. It is served using django.views.static.serve
#settings.py:
STATIC_DOC_ROOT = 'site_media/'
and
#urls.py:
urlpatterns = patterns('',
(...)
url(r'^site_media/(?P<path>.*)
Now, I just want to show smaller versions of these pictures on my site. I was hoping that there was an app with a template tag that could easily do this.
I am dreaming about smth like:
{% img "/site_media/foo.png" "100x100" %}
Which would create a resized picture somewhere in site_media, and then return the url for that, which could be "site_media/resized/foo_100x100.png".
I have been looking at Sorl-Thumbnail, but honestly I don't really understand how it operates. Sorry if I missed it, but it looks to me as if they never explain the flow from http request to response. And I am also not sure if Sorl even suits my problem.
, 'django.views.static.serve',
{'document_root': settings.STATIC_DOC_ROOT, 'show_indexes':True})
)
Now, I just want to show smaller versions of these pictures on my site. I was hoping that there was an app with a template tag that could easily do this.
I am dreaming about smth like:
{% img "/site_media/foo.png" "100x100" %}
Which would create a resized picture somewhere in site_media, and then return the url for that, which could be "site_media/resized/foo_100x100.png".
I have been looking at Sorl-Thumbnail, but honestly I don't really understand how it operates. Sorry if I missed it, but it looks to me as if they never explain the flow from http request to response. And I am also not sure if Sorl even suits my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有这样的事。我通常使用基于此自定义模板过滤器的内容:
http://djangosnippets.org/snippets/955/
There is such a thing. I normally use something based on this custom template filter:
http://djangosnippets.org/snippets/955/