Welut是一个电子书转换器
welut的Python项目详细描述
Welut is a ebook converter
要求
- 电子书转换:$ sudo apt install calibre-将epub&;mobi转换为pdf。
- pdftocairo:$ sudo apt install -ypoppler-utils-convert pdf to images
安装
欢迎直接从PyPI:
- 安装软件包。
$ pip install welut
- 别忘了把'welut'添加到'INSTALLED_APPS'中。
# settings.py INSTALLED_APPS = [ .... 'welut', ]
- 执行makemigration&migrate
./manage.py makemigrations welut ./manage.py migrate welut
配置(settings.py)
WELUT_EXTENSIONS = ['.pdf', '.epub', '.mobi'] # support file extensions WELUT_REMOVED_EXTENSIONS = ['.pdf', '.epub', '.mobi'] # file to remove after uploaded WELUT_IMAGES_EXTENSION = '.png' # format images extension
使用量
您可以使用ForeignKey或OneToOneField。
from django.db import models from welut.models import EbookConverter class EBook(models.Model): title = models.CharField(max_length=200) ebook_file = models.ForeignKey(EbookConverter, related_name='ebook_file') created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) def __str__(self): return self.title def get_files(self): """ return list images of ebook per-page """ return self.ebook_file.get_files()
模板
{% for img_url in object.get_files %} <img src="{{ MEDIA_URL }}{{ img_url }}"> {% endfor %}