Using: Flask, SQLAlchemy, Infinite-scroll
Created
September 22, 2014 18:29
-
-
Save scabbiaza/c3f2c2083370c6eb610e to your computer and use it in GitHub Desktop.
Flask with infinity scroll navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="js-infinite-item"> | |
== your data here == | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for model in models %} | |
{% include 'models/item.html' %} | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.js-infinite-layout').infinitescroll({ | |
itemSelector: '.js-infinite-item', | |
nextSelector: "div.js-infinite-navigation a:first", | |
navSelector: "div.js-infinite-navigation", | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Completely useless b*shit. Not working