小编Mun*_*nro的帖子

Python Wand将PDF转换为PNG禁用透明(alpha_channel)

我正在尝试将PDF转换为PNG - 这一切都运行正常,但是,即使我相信我已将其禁用,输出图像仍然是透明的:

with Image(filename='sample.pdf', resolution=300) as img:
    img.background_color = Color("white")
    img.alpha_channel = False
    img.save(filename='image.png')
Run Code Online (Sandbox Code Playgroud)

以上产生图像但透明,我也试过以下:

with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
    img.alpha_channel = False
    img.save(filename='image.png')
Run Code Online (Sandbox Code Playgroud)

产生此错误:

Traceback (most recent call last):
  File "file_convert.py", line 20, in <module>
    with Image(filename='sample.pdf', resolution=300, background=Color('white')) as img:
  File "/Users/Frank/.virtualenvs/wand/lib/python2.7/site-packages/wand/image.py", line 1943, in __init__
    raise TypeError("blank image parameters can't be used with image "
TypeError: blank image parameters can't be used with image opening parameters
Run Code Online (Sandbox Code Playgroud)

python imagemagick wand

18
推荐指数
3
解决办法
3万
查看次数

电子邮件上带有 unique_together 的 Django 自定义用户模型

我正在尝试在我的 Django 应用程序中创建一个自定义用户模型,问题是我收到一个错误,说电子邮件必须是唯一的(足够公平!),但是,我需要email并且company一起是唯一的,因为我可能有相同的电子邮件但注册到另一家公司。

我收到以下错误:

ERRORS:
site.SiteUser: (auth.E003) 'SiteUser.email' must be unique because it is named as the 'USERNAME_FIELD'.
Run Code Online (Sandbox Code Playgroud)

这是我的模型:

class SiteUser(models.Model):
    company = models.ForeignKey(Company)
    email = models.EmailField(max_length=254)

    is_staff = models.BooleanField(default=False)
    is_active = models.BooleanField(default=True)
    date_joined = models.DateTimeField(auto_now=False, auto_now_add=True)

    objects = SiteUserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    class Meta:
        unique_together = ('company', 'email',)
Run Code Online (Sandbox Code Playgroud)

python django

4
推荐指数
2
解决办法
4930
查看次数

标签 统计

python ×2

django ×1

imagemagick ×1

wand ×1