我正在尝试构建一个应用程序,我想在其中添加富文本编辑器。我已经添加了 CKEditor,它在管理面板上运行良好。我想知道是否有任何方法可以在没有
form.py
的情况下显示编辑器,只是为了保存简单的发布请求中的数据。
除了 forms.py 之外,还有其他方法来添加该编辑器吗? 提前谢谢你:)
模型.py
from django.db import models
from ckeditor.fields import RichTextField
# Create your models here.
class Profile(models.Model):
name = models.CharField(max_length=255)
email = models.EmailField(max_length=255)
previous_work = RichTextField(max_length=2000)
skills = RichTextField(max_length=2000)
html
<form class="container">
{% csrf_token %}
{{ form.media }}
<div class="mb-3">
<label class="form-label">Name</label>
<input type="text" class="form-control" name="name" id="name">
</div>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" name="email" id="email">
</div>
<div class="mb-3">
<label class="form-label">Previous Work</label>
<!-- <input type="number" class="form-control" name="summary" id="summary"> -->
<textarea name="Previous_work" class="form-control" id="Previous_work" cols="30" rows="10"></textarea>
</div>
<div class="mb-3">
<label class="form-label">Skills</label>
<!-- <input type="number" class="form-control" name="summary" id="summary"> -->
<textarea name="skills" class="form-control" id="skills" cols="30" rows="10"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
from ckeditor.fields import RichTextField
class CKModel(models.Model):
c = RichTextField()
def CKView(request):
form = CKForm()
if request.method == 'POST':
c= request.POST.get('skills')
CKModel(c=c).save()
return render(request,'index.html',{'form':form})
{% block body %}
<form action="" method="POST">
{% csrf_token %}
{{form.media}}
<textarea name="skills" class="form-control" id="editor" cols="30" rows="10"></textarea>
<button type="submit">add</button>
</form>
{% endblock body %}
我在 django-ckeditor-5 上遇到了完全相同的问题!你找到解决办法了吗?