使用 Django 进行 Pagedown(Markdown 编辑器)

发布于 2024-12-20 17:18:27 字数 365 浏览 5 评论 0原文

我尝试使用 pagedown(markdown 编辑器),这是我基于 django 的网站中 stackoverflow 的一个。然而,要在文本区域中获取 Markdown 编辑器,需要为文本区域提供 id 和 class,但是

<textarea id="wmd-input" class="wmd-input"/>

django 生成的表单字段的默认 id 为 id_。有没有办法可以为这个text_area分配相同的id?

I trying to use the pagedown(markdown editor), the one that stackoverflow in my django based website. However to get the markdown editor in a textarea it is required to give the text area both id and class as

<textarea id="wmd-input" class="wmd-input"/>

However the form fields generated by django have a default id as id_<field-name>. Is there a way I can assign the same id to this text_area?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥枳 2024-12-27 17:18:27

您也可以在传递类名的 models.py 中直接传递 id 。这将覆盖默认行为。

widgets = {
        '<attribute_name>': Textarea(attrs={'class':'wmd-input','id':'wmd-input'}),
            }

you can directly pass id as well in the models.py where your are passing class name. This will override the default behavior.

widgets = {
        '<attribute_name>': Textarea(attrs={'class':'wmd-input','id':'wmd-input'}),
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文