from . import models
from django.shortcuts import render
def Example(request):
object = models.objects.get(id=1)
return render(request, 'example.html', K8SContext)
from django.urls import path
from . import views
urlpatterns = [
path('test/', views.Example)
{% load static %}
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Title</title>
<link href="{% static 'mdeditor/css/editormd.min.css' %}" rel="stylesheet">
<link href="{% static 'mdeditor/css/editormd.preview.css' %}" rel="stylesheet">
</head>
<div> name: {{ object.name }}</div>
<div> content:
<div id="content"><textarea>{{ object.content }}</textarea></div>
{{ object.content_test }}
</div>
<script src="{% static 'mdeditor/js/jquery.min.js' %}"></script>
<script src="{% static 'mdeditor/js/editormd.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/marked.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/prettify.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/raphael.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/underscore.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/sequence-diagram.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/flowchart.min.js' %}"></script>
<script src="{% static 'mdeditor/js/lib/jquery.flowchart.min.js' %}"></script>
<script>
$(function () {
editormd.markdownToHTML("content", {
emoji : true,
taskList : true,
tex : true,
flowChart : true,
sequenceDiagram : true,
});
$(".reference-link").each(function (i,obj) {
console.log(obj)
</script>
</body>
</html>
Django 可以使用 Markdown 作为文本编辑器吗?当然可以,Markdown 语法简单,可以在本地任意编辑器里面修改,不会像 富文本编辑器 兼容性差。Django 怎样使用 Markdown 编辑器呢?安装pip install django-mdeditor在 settings 配置文件 INSTALLED_APPS 中添加 mdeditor: INSTALLED_APPS = [ ... 'mdeditor', ]
一、需求来源
近期有一个 django 前台使用 markdown 编辑器的需求,网上查了很多资料很多都是在后台使用 markdown 编辑器,然后在前台展示,可以参考。但是这种的教程对于想在前台页面使用 markdown 编辑器的人来说,属实是很难看懂啊。
所以我整理了一个完整的项目流程,包括前台编写和前台展示。附项目。
编写时间:2021年11月17日11:46:33
支持转发,但请注明出处。
二、先看效果
话不多少,先放效果图,看看是不是自己想要的那种效果,我这里放三张图【编辑页面、查看页面、管理页
最近自己在开发一个blog,因为比较喜欢用Markdown来写文章,而且目前很多平台都支持Markdown的语法,所以想给blog装个Markdown的编辑器。于是,就搜了一下,发现了django-mdeditor这个库,给大家分享一下。
Github地址: https://github.com/pylixm/django-mdeditor
Django-mdeditor 是基于 ...
2、引入css和js:
<link rel="stylesheet" href="{% static 'plugins/editor_md/css/editormd.css' %}">
<script src="{% static 'plugins/
Python Django富文本编辑器可以通过使用第三方库和插件来实现上传功能。常用的方法是使用django-ckeditor库或django-tinymce库来集成富文本编辑器以及上传功能。
首先,在Django项目中安装所需的库,可以通过在终端中运行以下命令安装库:
```python
pip install django-ckeditor
pip install django-tinymce
安装完成后,需要在Django的设置文件中进行相应的配置。对于django-ckeditor库,需要将以下内容添加到settings.py中的INSTALLED_APPS和STATIC_URL中:
```python
INSTALLED_APPS = [
'ckeditor',
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
对于django-tinymce库,需要将以下内容添加到settings.py中的INSTALLED_APPS和STATIC_URL中:
```python
INSTALLED_APPS = [
'tinymce',
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
然后,需要在urls.py文件中添加相应的URL配置。对于django-ckeditor库,可以添加以下代码:
```python
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from ckeditor_uploader import views as ckeditor_views
urlpatterns = [
path('ckeditor/', include('ckeditor_uploader.urls')),
path('admin/', admin.site.urls),
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
对于django-tinymce库,可以添加以下代码:
```python
from django.contrib import admin
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from tinymce import views as tinymce_views
urlpatterns = [
path('tinymce/', include('tinymce.urls')),
path('admin/', admin.site.urls),
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
最后,还需要进行一些前端和后端的配置。具体可以参考文档或库的使用说明来实现上传功能。
以上就是使用Python Django富文本编辑器实现上传功能的简要步骤。