Guest User

Untitled

a guest
Feb 13th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. **app.py**
  2.  
  3.  
  4. import os
  5. # flask imports
  6. from flask import Flask, flash, redirect, render_template, url_for
  7. from flask_sqlalchemy import SQLAlchemy
  8. from flask_ckeditor import CKEditor
  9. from flask_wtf import FlaskForm
  10.  
  11. from wtforms import SubmitField, TextAreaField
  12. from wtforms.validators import DataRequired
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. basedir = os.path.abspath(os.path.dirname(__file__))
  20.  
  21. # 1. Initialize Extensions (No longer importing SQLAlchemy twice)
  22. db = SQLAlchemy()
  23. # create the app
  24. app = Flask(__name__, static_folder='static')
  25. ckeditor = CKEditor(app)
  26.  
  27. # 2. Configuration
  28. app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db"
  29. app.config['SECRET_KEY']= 'secret_key'
  30.  
  31. # initialize the app with the extension
  32. db.init_app(app)
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. class CreateTiptapform(FlaskForm):
  40. # CKEditorField is correct for rich text input
  41. tiptap = TextAreaField('tiptap', validators=[DataRequired('Content is required')])
  42. submit = SubmitField('Submit')
  43.  
  44. # 6. Routes
  45.  
  46.  
  47.  
  48. @app.route('/testing_tiptap', methods = ['GET', 'POST'])
  49. def testing_tiptap():
  50. if request.method == 'POST':
  51. return redirect(url_for('home')) # Redirect to the check page
  52. return render_template('testing_tiptap.html', title='testing tiptap')
  53.  
  54.  
  55. # 7. Database Creation and App Run
  56. if __name__ == '__main__':
  57. with app.app_context():
  58. # Ensure tables are created before running the app
  59. db.create_all()
  60.  
  61. app.run(debug=True)
  62.  
  63.  
  64. **main.js**
  65.  
  66. import { Editor } from '@tiptap/core'
  67. import Document from '@tiptap/extension-document'
  68. import Paragraph from '@tiptap/extension-paragraph'
  69. import Text from '@tiptap/extension-text'
  70.  
  71. new Editor({
  72. // bind Tiptap to the `.element`
  73. element: document.querySelector('.element'),
  74. // register extensions
  75. extensions: [Document, Paragraph, Text],
  76. // set the initial content
  77. content: '<p>Example Text</p>',
  78. // place the cursor in the editor after initialization
  79. autofocus: true,
  80. // make the text editable (default is true)
  81. editable: true,
  82. // prevent loading the default ProseMirror CSS that comes with Tiptap
  83. // should be kept as `true` for most cases as it includes styles
  84. // important for Tiptap to work correctly
  85. injectCSS: false,
  86. })
  87.  
  88.  
  89. testing_tipap.html
  90.  
  91. <form action="" method="post" novalidate>
  92. <div class='element'></div>
  93. <script type="module" src="/static/src/main.js"></script>
  94. </form>
  95.  
Advertisement
Add Comment
Please, Sign In to add comment