Last active
August 8, 2016 04:21
-
-
Save commadelimited/2f0ae915f1d981e0b52d0bbf0e201859 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@app.route('/') | |
@app.route('/page/<int:page_number>/') | |
def index(page_number=1): | |
path = '' if request.url_rule.rule == '/' else request.url.replace(request.url_root, '/') | |
context = { | |
'pagination': Pagination(page_number, settings.PER_PAGE, sorted_pages), | |
'canonical_url': '{root}{path}'.format(root=settings.ROOT_URL, path=path) | |
} | |
return render_template('index.html', context=context) |
I'm specifically looking for how to allow for multiple routes pointing to the same code. In the Pluggable View documentation an example is given which allows for multiple pointers to the same View because of HTTP request type. In my case I'm using almost the same code, but different templates.
# This one's easy enough
app.add_url_rule('/', view_func=IndexView.as_view('index'))
# But how do I reference the same view for the paging?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do I convert the above code into a Pluggable view?