quill get content flask
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/get_quill_content', methods=['POST'])
def get_quill_content():
data = request.get_json()
quill_content = data.get('quillContent')
# Process quill_content as needed
# Example: return quill_content as a JSON response
return {'quillContent': quill_content}
if __name__ == '__main__':
app.run(debug=True)
Create a new file named index.html
in the templates
folder:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quill Content Example</title>
<!-- Include Quill CSS -->
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
</head>
<body>
<div id="editor"></div>
<button onclick="submitQuillContent()">Submit</button>
<!-- Include Quill JS -->
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<script>
var quill = new Quill('#editor', {
theme: 'snow',
placeholder: 'Write something...',
});
function submitQuillContent() {
var quillContent = quill.root.innerHTML;
// Send quillContent to the server
fetch('/get_quill_content', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ quillContent: quillContent }),
})
.then(response => response.json())
.then(data => console.log(data));
}
</script>
</body>
</html>
Ensure that the necessary Flask and Quill dependencies are installed:
pip install Flask
Run the Flask application:
python your_app_name.py
Visit http://127.0.0.1:5000/
in your web browser, and you can use the Quill editor to input content. Press the "Submit" button to send the content to the server, where it will be printed in the console.