Comments (1)
It depends on the tool you use. For example, if you use Flask-WTF and Flask-SQLAlchemy, then the save/upload operation will just like any normal form input:
import os
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
from flask_sqlalchemy import SQLAlchemy
from flask_ckeditor import CKEditor, CKEditorField
app = Flask(__name__)
app.secret_key = 'secret string'
ckeditor = CKEditor(app)
db = SQLAlchemy(app)
class Post(db.Model): # database model class
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(64))
body = db.Column(db.Text)
class PostForm(FlaskForm): # form class
title = StringField('Title')
body = CKEditorField('Body', validators=[DataRequired()])
submit = SubmitField('Submit')
@app.route('/write', methods=['GET', 'POST'])
def write():
form = PostForm()
if form.validate_on_submit(): # create new post
title = form.title.data
body = form.body.data
post = Post(title=title, body=body) # create record instance
db.session.add(post) # add to database session
db.session.commit() # commit change into database
return render_template('post.html', title=title, body=body)
return render_template('write.html', form=form)
@app.route('/edit/<int:post_id>', methods=['GET', 'POST'])
def edit(post_id):
post = Post.query.get_or_404(post_id) # query post in database
form = PostForm()
if form.validate_on_submit(): # edit/update created post
post.title = form.title.data # set new value
post.body = form.body.data # set new value
db.session.commit() # commit change into database
return render_template('post.html', title=title, body=body)
form.body.data = post.body # preset the form input data
return render_template('edit.html', form=form)
You can check Flask-SQLAlchemy's documentation for more infomation.
from flask-ckeditor.
Related Issues (20)
- codesnippet plugin 404 with CKEDITOR_SERVE_LOCAL = False HOT 4
- 如果我想实现文字居右,应该如何操作呢? HOT 1
- Image Upload Issue HOT 1
- AttributeError: 'NoneType' object has no attribute 'filename' HOT 5
- Add configuration CKEDITOR_CONTENTS_CSS
- is there a way to add babel/babelex support to translate the editor labels? HOT 8
- Documentation not available HOT 3
- Add example for external file browser integration
- Drop Python 2 support
- Move CI to GitHub Actions
- CKEditor fillEmptyBlocks Configuration
- Flask-CKEditor 1.0 Plan
- Markup removed in Flask 3.0.0 HOT 2
- Add readthedocs config file
- Format keys not working
- cleanify is missing HOT 1
- Code Snippet plugin not working in rendered HTML
- Where does the CKEditor Bundle go? HOT 2
- there is no static folder in pypi package 0.5.1
- there is no static folder in pypi package 0.5.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-ckeditor.