引入 wagtail-markdown
使 Wagtail
在編輯文章時支持 Markdown
語法,提高編寫效率和通用性。
pip install wagtail-markdownpip install wagtailfontawesomepip install Pygments
wagtail-markdown 安裝過程會將 django和wagtail 替換為舊版本,安裝后需要執(zhí)行下面命令,手工修復(fù) wagtail,django 為指定版本,其他版本未測試
pip install django==2.1pip install wagtail==2.4
python 終端中,輸入下面命令:
from pygments.formatters import HtmlFormatterprint(HtmlFormatter().get_style_defs('.codehilite'))
輸入內(nèi)容拷貝存儲為 pygments.css
,放入項目 /slowread/static/css
文件目錄,在頁面模板文件中加入一行:
<link rel="stylesheet" type="text/css" href="{% static 'path/to/pygments.css' %}">
修改 /slowread/settings/base.py
在 INSTALLED_APPS
中增加:
INSTALLED_APPS += [ 'wagtailmarkdown',]
修改 /slowread/blog/models.py
,增加 Markdown StreamField block
配置:
from wagtailmarkdown.blocks import MarkdownBlockclass BlogPage(Page): author = models.CharField("Author", max_length=255, default="SlowRead.Net") date = models.DateField("Post date") intro = models.CharField(max_length=250) # body = RichTextField(blank=True) body = StreamField([ ('heading', blocks.CharBlock(classname="full title")), ('paragraph', 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
如果一切正常,在后臺管理界面編輯文章應(yīng)該可以增加 Markdown
區(qū)塊,并且可以即時預(yù)覽/發(fā)布了。
在項目的\.vscode\launch.json
文件修改 Python
環(huán)境路徑:
"python.pythonPath": "G:\\project_demo\\venv\\Scripts\\python.exe",
參考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
,因為在此系統(tǒng)上禁止運行腳本。有關(guān)詳細(xì)信息,請參閱 http://go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies
。
解決辦法:
PowerShell
set-executionpolicy remotesigned
pip install redis-cli-cluster