flask - How to save markdown from a WTForm in a database using SQLAlchemy? -


i have blog making create posts in 'edit' route using markdown in text area box. however, when save post, converts of formatting in weird ways. instance, when have apostrophe, such in word doesn't this:

doesn't 

here form code:

class item(db.model):     __tablename__= 'item'     id = db.column(db.integer,primary_key=true)     title = db.column(db.string(80),unique=false)     content = db.column(db.string(80),unique=false)     x = db.column(db.float)     y = db.column(db.float)     category_id = db.column(db.integer, db.foreignkey('category.id'))     order = db.column(db.integer)      def __init__(self,title,content,x,y,category_id,order):         self.title = title         self.content = content         self.x = x         self.y = y         self.category_id = category_id         self.order = order 

here edit route handles saving object in sqlalchemy:

@app.route('/edit/<itemid>',methods=('get','post')) @requires_auth def edit(itemid):     item = item.query.get(itemid)     c = category.query.get(item.category_id)     form = itemform()     form.title.data=item.title     category = c.name     form.content.data=item.content     if request.method == 'post':         if request.form.get('title'):             item.title = request.form['title']             item.content = request.form['content']             print item.content, 'conetnt'             db.session.add(item)             db.session.commit()             return redirect(url_for('view',itemid=item.id))         else:             flash('title , content , category required.','danger')     return render_template('edit.html',item=item,form=form, category=category) 

and here template:

<div id="container" style="padding:10px">         <form method="post" action="{{ url_for('edit',itemid=item.id) }}" id="text-input">             {{ form.csrf_token }}             <div style="margin-left:30px;margin-top:20px;">                 title: {{ form.title }} {{ category }}             </div>             <br>              <div id="editor">             {{ form.content( **{':value':'input','@input': 'update'}) }}                 <div id="preview" v-html="compiledmarkdown"></div>             </div>             <br>             <input type="submit" value="save" class="btn btn-secondary" >         </form> </div> 

as can see have editor filled content using {{ form.content( **{':value':'input','@input': 'update'}) }} using vue.js create markdown preview of text - interestingly shows things formatted correctly until opens saved file. believe template passing data server incorrectly. because when print content in server code before saving in database, formatted incorrectly.

how do correctly?


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -