miguelgrinberg / Flask-PageDown

Implementation of StackOverflow's "PageDown" markdown editor for Flask and Flask-WTF.
MIT License
244 stars 21 forks source link

Companion code in README.md can't run correctly? #12

Closed Abirdcfly closed 8 years ago

Abirdcfly commented 8 years ago

here are my code:

# app/__init__.py
...
from flask.ext.pagedown import PageDown
...
pagedown = PageDown()
...
def create_app():
  pagedown.init_app(app)
...

That's Class define:

# main\forms.py
from flask.ext.wtf import Form
from wtforms import StringField, SubmitField
from flask.ext.pagedown.fields import PageDownField

class PostForm(Form):
article_title = StringField('title')
body = PageDownField('body')
submit = SubmitField('submmit')

It's right.

# main\views.py
from .forms import PostForm

@main.route('/post', methods=['GET', 'POST'])
@login_required
def post():
    title = 'edit'
    form = PostForm()
    if form.validate_on_submit():
        posts = Post( body=form.body.data,
                     author=current_user._get_current_object())
        db.session.add(posts)
        flash('commit')
        return redirect(url_for('main.doc'))
    return render_template('post.html', title=title, form=form)

here is html file:

{# post.html #}
{% extends "base.html" %}
{% block head %}
    {{ super() }}
    {{ pagedown.include_pagedown() }}
{% endblock %}

{% block page_content %}
<div class="page-header">
    <div class="row">
        <div class="col-md-6">
             <form method="POST">
            {{ form.pagedown(only_input=True, rows=10) }}
            {{ form.submit }}
             </form>
        </div>
        <div class="col-md-6">
            {{ form.pagedown(only_preview=True) }}
        </div>
    </div>
</div>
{% endblock %}]

I GOT A WRONG

UndefinedError: 'app.main.forms.PostForm object' has no attribute 'pagedown'

Abirdcfly commented 8 years ago

I am wrong THX