Skip to content

Instantly share code, notes, and snippets.

@commadelimited
Last active August 8, 2016 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commadelimited/2f0ae915f1d981e0b52d0bbf0e201859 to your computer and use it in GitHub Desktop.
Save commadelimited/2f0ae915f1d981e0b52d0bbf0e201859 to your computer and use it in GitHub Desktop.
@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)
@commadelimited
Copy link
Author

how do I convert the above code into a Pluggable view?

@commadelimited
Copy link
Author

commadelimited commented Aug 7, 2016

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