Skip to content

Instantly share code, notes, and snippets.

@scabbiaza
Created September 22, 2014 18:29
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scabbiaza/c3f2c2083370c6eb610e to your computer and use it in GitHub Desktop.
Save scabbiaza/c3f2c2083370c6eb610e to your computer and use it in GitHub Desktop.
Flask with infinity scroll navigation

Flask with infinity scroll navigation

Using: Flask, SQLAlchemy, Infinite-scroll

<html>
<body>
<div class="container">
{% if models %}
<div class="js-infinite-layout">
{% include "models/items.html" %}
<div class="js-infinite-navigation">
<a href="{{ request.url }}/page/{{ page + 1 }}"></a>
</div>
</div>
{% else %}
<p class="alert alert-info">
No jobs yet
</p>
{% endif %}
</div>
<script src="/static/dist/js/jquery/jquery.infinitescroll.js"></script>
<script src="/static/dist/js/theme.js"></script>
</body>
</html>
<div class="js-infinite-item">
== your data here ==
</div>
{% for model in models %}
{% include 'models/item.html' %}
{% endfor %}
$('.js-infinite-layout').infinitescroll({
itemSelector: '.js-infinite-item',
nextSelector: "div.js-infinite-navigation a:first",
navSelector: "div.js-infinite-navigation",
});
from flask import current_app, render_template
@bp.route('')
@bp.route('/page/<int:page>')
def index(page=1):
per_page = current_app.config['PER_PAGE']
models = Model.query.paginate(page, per_page, False).items
tmpl_name = 'models/index.html' if page == 1 else 'models/items.html'
return render_template(tmpl_name, models=models, page=page)
@rlam3
Copy link

rlam3 commented Jul 11, 2015

Is this still the prefered way or is there a better way for this now?

@Maestro12345678
Copy link

Completely useless b*shit. Not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment