轻松记录您
灵感和创意

Wagtail 教程 9:支持 Markdown

Wagtail是一个用Python编写的开源CMS,基于Django框架构建。它优雅,强大,敏捷,专注于从而和用户体验,为开发人员提供一个快速的界面,可以直观地创建和组织内容。

Wagtail教程系列记录了构建博客站点的整个过程,当前站点所呈现的即是建造过程的最新效果。

参考 https://github.com/torchbox/wagtail-Markdown/

约会wagtail-Markdown使Wagtail在编辑文章时支持Markdown语法,提高编写效率和通用性。

安装wagtail-Markdown与相关包

点安装wagtail-Markdown

点安装wagtailfontawesome

点安装Pygments

wagtail-Markdown安装过程将django和wagtail替换为旧版本,安装后需要执行以下命令,手工修复wagtail,django为指定版本,其他版本未测试

点安装django == 2.1

点安装wagtail == 2.4

代码高亮

python终端中,输入以下命令:

从pygments.formatters导入HtmlFormatter

打印(HtmlFormatter()。get_style_defs(’。codehilite’))

输入内容拷贝存储为pygments.css,加入项目/slowread/static/css文件目录,在页面模板文件中加入一行:

配置内容

修改/slowread/settings/base.py在INSTALLED_APPS中增加:

INSTALLED_APPS + = [

‘wagtailMarkdown‘,

]

修改/slowread/blog/models.py,增加Markdown StreamField block配置:

从wagtailMarkdown.blocks导入MarkdownBlock

类BlogPage(Page):

作者= models.CharField(“作者”,max_length = 255,默认=“ SlowRead.Net”)

日期= models.DateField(“发布日期”)

简介= models.CharField(max_length = 250)

#body = RichTextField(blank = True)

正文= StreamField([

(“标题”,blocks.CharBlock(classname =“完整标题”)),

(“段落”,blocks.RichTextBlock()),

(‘code’, CodeBlock(label=’Code’)),

(‘blockquote’, blocks.BlockQuoteBlock(label=’Block Quote’)),

(‘image’, ImageChooserBlock(label=’Image Chooser’)),

(‘url’, blocks.URLBlock(label=’URL’)),

(’embed’, EmbedBlock(label=’Embed’)),

(‘documentchooser’, DocumentChooserBlock(label=’Document Chooser’)),

(‘rawhtml’, blocks.RawHTMLBlock(label=’Raw HTML’)),

(‘table’, TableBlock(label=’Table’)),

(‘Markdown‘, MarkdownBlock(label=’Markdown‘)),

])

增加了下面一行:

(‘Markdown‘, MarkdownBlock(label=’Markdown‘)),

执行静态文件归集

python manage.py collectstatic –noinput

完成

如果一切正常,在后台管理界面编辑文章应该可以增加 Markdown 区块,并且可以即时预览/发布了。

问题备忘

VS Code 使用 virtualenv 中的 Python 环境

在项目的\.vscode\launch.json 文件修改 Python 环境路径:

“python.pythonPath”: “G:\\project_demo\\venv\\Scripts\\python.exe”,

Django 日志记录

参考 https://stackoverflow.com/questions/35945857/server-error-500-wagtail-admin

Try to run:

python manage.py collectstatic –noinput

Missing static files when DEBUG = False will cause 500 server error.

To see exactly what was the issue enable logging to a file by adding the following to the settings module (generally: settings.py):

#”’

LOGGING = {

‘version’: 1,

‘disable_existing_loggers’: False,

‘formatters’: {

‘verbose’: {

‘format’ : “[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s”,

‘datefmt’ : “%d/%b/%Y %H:%M:%S”

},

‘simple’: {

‘format’: ‘%(levelname)s %(message)s’

},

},

‘handlers’: {

‘file’: {

‘level’: ‘DEBUG’,

‘class’: ‘logging.FileHandler’,

‘filename’: ‘your_site_name.log’,

‘formatter’: ‘verbose’

},

},

‘loggers’: {

‘django’: {

‘handlers’:[‘file’],

‘propagate’: True,

‘level’:’DEBUG’,

},

‘MYAPP’: {

‘handlers’: [‘file’],

‘level’: ‘DEBUG’,

},

}

}

#”’

This will log details about the error in ‘your_site_name.log’ in your project directory (you can also provide an absolute path).

When finished debugging just remove the first hash ‘#’ from the code above to comment it and keep it for future debugging.

无法加载文件…\venv\scripts\activate.ps1

错误信息:

无法加载文件…\venv\scripts\activate.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。

解决办法:

以管理员身份打开PowerShell

执行命令set-executionpolicy remotesigned

ValueError: Redis URL must specify one of the followingschemes (redis://

pip install redis-cli-cluster

未经允许不得转载:坚果云Markdown » Wagtail 教程 9:支持 Markdown
分享到: 更多 (0)

坚果云Markdown轻松记录您 灵感和创意

坚果云Markdown下载坚果云Markdown介绍