def edit_page(page_name):
    if request.method == 'GET':
        contents = get_page(page_name)
        if contents is None:
            abort(404)

        title = get_page_display_name(page_name)

        return render_template('edit_page.html', page_name=title, contents=contents)

    title = request.form['title']
    contents = request.form['contents']

    update_page(get_page_url_name(title), contents)
    # Save updated page with provided contents (get_page_url_name(title) helper method)

    return redirect(url_for('page', page_name=get_page_url_name(title)))
def edit_page(page_name):
    if request.method == 'GET':
        with open('pages/' + page_name + '.md') as page_file:
            contents = page_file.read()

        title = get_page_display_name(page_name)

        return render_template('edit_page.html',
                               page_name=title,
                               contents=contents)

    title = request.form['title']
    contents = request.form['contents']

    with open('pages/' + get_page_url_name(title) + '.md', 'w') as page_file:
        page_file.write(contents)

    return redirect(url_for('page', page_name=get_page_url_name(title)))
def new_page():
    if request.method == 'GET':
        return render_template('new_page.html')

    title = request.form['title']
    contents = request.form['contents']

    create_page(get_page_url_name(title), contents)
    # Save new page with provided title and contents (get_page_url_name(title) helper method)

    return redirect(url_for('pages'))
def new_page():
    if request.method == 'GET':
        return render_template('new_page.html')

    ensure_pages_directory_exists()

    title = request.form['title']
    contents = request.form['contents']

    with open('pages/' + get_page_url_name(title) + '.md', 'w') as page_file:
        page_file.write(contents)

    return redirect(url_for('pages'))