Browse Source

Chapter 11: Rich text blog posts with Flask-PageDown (11e)

master
T. Meissner 6 years ago
parent
commit
f7110f653e
5 changed files with 35 additions and 1 deletions
  1. +3
    -0
      app/__init__.py
  2. +2
    -1
      app/main/forms.py
  3. +24
    -0
      app/static/styles.css
  4. +5
    -0
      app/templates/index.html
  5. +1
    -0
      requirements/common.txt

+ 3
- 0
app/__init__.py View File

@ -4,6 +4,7 @@ from flask_mail import Mail
from flask_moment import Moment from flask_moment import Moment
from flask_sqlalchemy import SQLAlchemy from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager from flask_login import LoginManager
from flask_pagedown import PageDown
from config import config from config import config
@ -11,6 +12,7 @@ bootstrap = Bootstrap()
mail = Mail() mail = Mail()
moment = Moment() moment = Moment()
db = SQLAlchemy() db = SQLAlchemy()
pagedown = PageDown()
login_manager = LoginManager() login_manager = LoginManager()
@ -27,6 +29,7 @@ def create_app(config_name):
moment.init_app(app) moment.init_app(app)
db.init_app(app) db.init_app(app)
login_manager.init_app(app) login_manager.init_app(app)
pagedown.init_app(app)
from .main import main as main_blueprint from .main import main as main_blueprint
app.register_blueprint(main_blueprint) app.register_blueprint(main_blueprint)


+ 2
- 1
app/main/forms.py View File

@ -3,6 +3,7 @@ from wtforms import StringField, SubmitField, TextAreaField, BooleanField, \
SelectField SelectField
from wtforms.validators import DataRequired, Length, Email, Regexp from wtforms.validators import DataRequired, Length, Email, Regexp
from wtforms import ValidationError from wtforms import ValidationError
from flask_pagedown.fields import PageDownField
from ..models import Role, User from ..models import Role, User
@ -51,5 +52,5 @@ class EditProfileAdminForm(FlaskForm):
class PostForm(FlaskForm): class PostForm(FlaskForm):
body = TextAreaField("What's on your mind?", validators=[DataRequired()])
body = PageDownField("What's on your mind?", validators=[DataRequired()])
submit = SubmitField('Submit') submit = SubmitField('Submit')

+ 24
- 0
app/static/styles.css View File

@ -37,3 +37,27 @@ div.pagination {
padding: 0px; padding: 0px;
margin: 0px; margin: 0px;
} }
div.flask-pagedown-preview {
margin: 10px 0px 10px 0px;
border: 1px solid #e0e0e0;
padding: 4px;
}
div.flask-pagedown-preview h1 {
font-size: 140%;
}
div.flask-pagedown-preview h2 {
font-size: 130%;
}
div.flask-pagedown-preview h3 {
font-size: 120%;
}
.post-body h1 {
font-size: 140%;
}
.post-body h2 {
font-size: 130%;
}
.post-body h3 {
font-size: 120%;
}

+ 5
- 0
app/templates/index.html View File

@ -23,3 +23,8 @@
</div> </div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block scripts %}
{{ super() }}
{{ pagedown.include_pagedown() }}
{% endblock %}

+ 1
- 0
requirements/common.txt View File

@ -8,6 +8,7 @@ Flask-Login==0.4.1
Flask-Mail==0.9.1 Flask-Mail==0.9.1
Flask-Migrate==2.2.1 Flask-Migrate==2.2.1
Flask-Moment==0.6.0 Flask-Moment==0.6.0
Flask-PageDown==0.2.2
Flask-SQLAlchemy==2.3.2 Flask-SQLAlchemy==2.3.2
Flask-WTF==0.14.2 Flask-WTF==0.14.2
itsdangerous==0.24 itsdangerous==0.24


Loading…
Cancel
Save