Django 缩略图,简单

发布于 2024-11-19 15:36:00 字数 699 浏览 0 评论 0原文

我有一个包含静态内容的文件夹,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§普罗旺斯的薰衣草 2024-11-26 15:36:00

有这样的事。我通常使用基于此自定义模板过滤器的内容:

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文