上传图片中的django水印程序

时间:2014-03-02 07:11:50

标签: python django watermark

我正在使用django水印为我的网站图像添加水印。我已根据此https://pypi.python.org/pypi/django-watermark/完成了所有设置。

这是我的settings.py文件(此处仅显示与水印关联的更改)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'django.contrib.admin',

    'photo',
    'userena',
    'guardian',
    'easy_thumbnails',
    'accounts',

    'paypal.standard.ipn',
    'myprofile',
    'watermarker',

WATERMARKING_QUALITY = 85
WATERMARK_OBSCURE_ORIGINAL = False

现在根据上面的链接,我已经在我的数据库的水印表中上传了一个透明的PNG图像,即医学艺术,现在我已经在以下模板中应用了水印......

{% extends 'base.html'%}
{% load watermark %}
{% block title %}ShutterStock{%endblock%}


{% block content %}



 <ul> 

{% for photo in photo_list%}
  <li><a href = "{% url 'download_image' photo.id %}"><img src={{photo.photo.url|watermark: 'Medical Art,opacity=40,tile=1'}} alt = 'sample photo' width = '200' height = '200'/></li></a>
{% endfor %}
</ul>





{% endblock %}

提到,我显示的图像是上传的图像。但是我在运行网站后收到以下错误,即

/ showphoto /

的IOError

解码器zip不可用

1 个答案:

答案 0 :(得分:0)

删除filter和参数:

之间的空格
{{photo.photo.url|watermark: 'Medical Art,opacity=40,tile=1'}}
                            ^

示例:

  • 没有空格:

    >>> from django.template import Template, Context
    >>> Template('''{{nothing|default:'HELLO'}}''').render(Context({}))
    u'HELLO'
    
  • 空格:

    >>> Template('''{{nothing|default: 'HELLO'}}''').render(Context({}))
    Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 125, in __init__
        self.nodelist = compile_string(template_string, origin)
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 153, in compile_string
        return parser.parse()
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 254, in parse
        filter_expression = self.compile_filter(token.contents)
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 360, in compile_filter
        return FilterExpression(token, self)
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 572, in __init__
        self.args_check(filter_name, filter_func, args)
      File "/home/falsetru/.virtualenvs/django16/local/lib/python2.7/site-packages/django/template/base.py", line 641, in args_check
        (name, len(nondefs), plen))
    TemplateSyntaxError: default requires 1 arguments, 0 provided