admin管理员组

文章数量:1122832

What I want to do is add a LaTeX button when using flask CKeditor in a form. Then I want to get the ckeditor value in the column from a database and display the jinja db column in the html file so the LaTeX typed equations display.

I also require the LaTeX extension to be free. I think /, would be good for the LaTeX button. But other free LaTeX can also work if anyone has any suggestion.

Here is what I tried.

I am trying to render {{post.content}} in html when using flask ckeditor with flask wtf but the problem is I am getting a character like &nbsp. Below is a better example of what I am talking about . <p>zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz</p> <p>&nbsp;</p> <p>zzzzzzzzzzzzzzzzzzzzzzzzzzzz</p> .

How do I fix this so it displays in html using jinja like it is in flask ckeditor form? I just wanted to add the extra character like &nbsp is caused by the flask ckeditor form.

(Also I may have mistyped one of the variable names because I changed some of the variable names to simplify this example. Also I just want to reiterate this works I just getting extra characters.)

Here is the code.

models.py

class Post(UserMixin, db.Model)
    # Here is the column in the class in models.py
    content: Mapped[Optional[str]] = mapped_column(Text(), unique=True)

forms.py

class CreateContentForm(FlaskForm):
    # todo change  to create_text
    create_content = CKEditorField('content', validators=[DataRequired('content is required')])
    submit = SubmitField('Submit')

routes.py

@postroute.route("/create_post_content", methods = ['GET', 'POST'])  
@login_required
def create_post_content():
    form = CreateContentForm()
    if form.validate_on_submit():
        content_form = form.create_content.data
        post_db = db.session.execute(db.select(Post).filter_by(contnet=content_form)).scalar_one_or_none()
        add_post_content = Post(content=text_form)
        db.session.add(add_post_content)    
        db.sessionmit()
        flash('You have created new content for the post successfully.')
        # redirect somewhere
    return render_template('create_post_content.html', title='create post content', form=form)  

post.html

{% extends "layout.html" %}
<!-- get the error message from wtf forms -->
    
{% from "_formhelpers.html" import render_field %}
{% block title %}  {{title}}  {% endblock title %}
   
    
 {% block content %}  
    <!--
    
    get the error message from ( "\_formhelpers.html" import render\_field)
    
    and make the error message from wtf forms show up on the screen. %}
    
    \-->
    
    <!-- I am not using bootstrap becauase it screws up ckeditor -->
    
    <form action="" method="post" novalidate>

    <!-- Make the secret key work -->

    {{ form.csrf_token }}
    {{ render_field(form.create_content) }}
    <input type="submit" value="Submit">  
    </form>
    
    {{ ckeditor.load() }}
    {{ ckeditor.config(name='create_content') }}
{% endblock content %}

_formshelpers.html

 <!--creates function that show the functions name and the error in flask wtf forms -->
{% macro render_field(field) %}
    <dt>{{ field.label }}
    <dd>{{ field(**kwargs)|safe }}
    {% if field.errors %}
        <ul class=errors>
        {% for error in field.errors %}
            <li>{{ error }}</li>
        {% endfor %}
        </ul>
    {% endif %}
    </dd>
{% endmacro %}

layout.html


<!DOCTYPE html>
<html>
<head> 
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Bootstrap CSS -->
    <link href="/[email protected]/dist/css/bootstrap.min.css" 
    rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">      
    <!-- CSS -->
    <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">

    
    {% if title %}
    <title> flashblog {{+ title}} </title>
    <!-- The title will say home -->
    {% else %} 
           {{ 'home' }}
    {% endif %}

   


</head>
<body>
    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="/[email protected]/dist/js/bootstrap.bundle.min.js" 
    integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>


 
    <!-- include the navbar which contains the searchform -->
    {% include 'navbar.html' %}
    
   

    {% block content %} 
    {% endblock content %}
 

    {% with messages = get_flashed_messages() %}
        {% if messages %}
            <ul class=flashes>
                {% for message in messages %}
                    <li>{{ message }}</li>
                {% endfor %}
            </ul>
        {% endif %}
   {% endwith %}    

</body>
</html>

本文标签: pythonHow do I add an extra button to flaskckeditorStack Overflow