我尝试将markdown插件martor应用到我的博客项目中,该项目在Django Admin中提供了一个漂亮的工具栏。然后我按照其说明将更改应用到我的models.py并期望在我的前端博客文章编辑器中查看相同的工具栏。但它不起作用(看起来像这样:。
我也尝试了post中的建议,但仍无效。
这是我的代码(model.py):
## models.py
from django.db import models
from django.utils import timezone
from martor.models import MartorField
class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)
#text = models.TextField()
text = MartorField()
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
并且forms.py
## forms.py
from django.forms import ModelForm
from martor.fields import MartorFormField
from martor.widgets import AdminMartorWidget
from .models import Post, Comment
class PostForm(ModelForm):
class Meta:
model = Post
fields = ('title', 'text',)
如何将Django Admin(图1)中的markdown工具栏添加到我的博客编辑页面?提前谢谢!
答案 0 :(得分:0)
答案 1 :(得分:0)
在将它们添加到模板之前,我遇到了同样的问题。 skippyho提供了一个链接,但这是代码:
<link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
<link href="{% static 'plugins/css/semantic.min.css' %}" type="text/css" media="all" rel="stylesheet" />
<link href="{% static 'plugins/css/resizable.min.css' %}" type="text/css" media="all" rel="stylesheet" />
<link href="{% static 'martor/css/martor.min.css' %}" type="text/css" media="all" rel="stylesheet" />
和
<script type="text/javascript" src="{% static 'plugins/js/ace.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/semantic.min.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/mode-markdown.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/ext-language_tools.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/theme-github.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/resizable.min.js' %}"></script>
<script type="text/javascript" src="{% static 'plugins/js/emojis.min.js' %}"></script>
<script type="text/javascript" src="{% static 'martor/js/martor.min.js' %}"></script>