Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solves the url redirect rule problem #51

Merged
merged 1 commit into from May 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions examples/wiki/wiki.py
Expand Up @@ -9,6 +9,10 @@
WIKIPART = re.compile(r'([A-Z][a-z0-9_]+)')
WIKIWORD = re.compile(r'([A-Z][a-z0-9_]+(?:[A-Z][a-z0-9_]+)+)')

@app.route('/', methods=['GET'])
def redirect():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will shadow "redirect" imported from flask module... should probably rename to homepage_redirect or something like that (that's what it was called before).

return redirect(url_for('HomePage'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think url_for works this way. I think you have to give it the name of an endpoint (show_page in this case) with whatever arguments that endpoint accepts. You probably want something like url_for("show_page", page="HomePage" -- but please test to be sure I'm not making this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll mess with it a little more extensively later tonight but that should be it.


@app.template_filter()
def totitle(value):
return ' '.join(WIKIPART.findall(value))
Expand All @@ -22,14 +26,14 @@ def wikify(value):
parts[i] = '[%s](%s)' % (name, url_for('show_page', pagepath=part))
return markdown2.markdown(''.join(parts))


@app.route('/<path:pagepath>')
def show_page(pagepath):
page = mongo.db.pages.find_one_or_404({'_id': pagepath})
return render_template('page.html',
page=page,
pagepath=pagepath)

app.add_url_rule('/', 'homepage_redirect', redirect_to='/HomePage')

@app.route('/edit/<path:pagepath>', methods=['GET'])
def edit_page(pagepath):
Expand Down Expand Up @@ -67,9 +71,7 @@ def save_upload(filename):
return redirect(url_for('get_upload', filename=filename))
return render_template('upload.html', filename=filename)


if __name__ == '__main__':
import doctest
doctest.testmod()
app.run(debug=True)