Chapter 12: Dates and Times (v0.12)

This commit is contained in:
Miguel Grinberg 2017-09-28 22:28:20 -07:00
parent b71c901c5a
commit a871e7b5dd
No known key found for this signature in database
GPG Key ID: 36848B262DF5F06C
4 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,7 @@ from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate from flask_migrate import Migrate
from flask_login import LoginManager from flask_login import LoginManager
from flask_mail import Mail from flask_mail import Mail
from flask_moment import Moment
from config import Config from config import Config
app = Flask(__name__) app = Flask(__name__)
@ -15,6 +16,7 @@ migrate = Migrate(app, db)
login = LoginManager(app) login = LoginManager(app)
login.login_view = 'login' login.login_view = 'login'
mail = Mail(app) mail = Mail(app)
moment = Moment(app)
if not app.debug: if not app.debug:
if app.config['MAIL_SERVER']: if app.config['MAIL_SERVER']:

View File

@ -9,7 +9,7 @@
<a href="{{ url_for('user', username=post.author.username) }}"> <a href="{{ url_for('user', username=post.author.username) }}">
{{ post.author.username }} {{ post.author.username }}
</a> </a>
says: said {{ moment(post.timestamp).fromNow() }}:
<br> <br>
{{ post.body }} {{ post.body }}
</td> </td>

View File

@ -54,5 +54,6 @@
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
{{ moment.include_moment() }}
</body> </body>
</html> </html>

View File

@ -7,7 +7,9 @@
<td> <td>
<h1>User: {{ user.username }}</h1> <h1>User: {{ user.username }}</h1>
{% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %} {% if user.about_me %}<p>{{ user.about_me }}</p>{% endif %}
{% if user.last_seen %}<p>Last seen on: {{ user.last_seen }}</p>{% endif %} {% if user.last_seen %}
<p>Last seen on: {{ moment(user.last_seen).format('LLL') }}</p>
{% endif %}
<p>{{ user.followers.count() }} followers, {{ user.following.count() }} following.</p> <p>{{ user.followers.count() }} followers, {{ user.following.count() }} following.</p>
{% if user == current_user %} {% if user == current_user %}
<p><a href="{{ url_for('edit_profile') }}">Edit your profile</a></p> <p><a href="{{ url_for('edit_profile') }}">Edit your profile</a></p>