from flask import Flask, render_template, url_for, Markup
from flask.ext.libsass import *
import pkg_resources
import markdown

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/<page>')
def get_page(page):
	md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
	html=Markup(markdown.markdown(md.read(), output_format='html5'))
	md.close()
	if page=='index':
		return render_template('page.html', content=html)
	return render_template('page.html', content=html, title=page)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()

from flask import Flask, render_template, url_for, Markup, abort
from flask.ext.libsass import *
import pkg_resources
import markdown

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/<page>')
def get_page(page):
	try:
		md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
		html=Markup(markdown.markdown(md.read(), output_format='html5'))
		md.close()
		if page=='index':
			return render_template('page.html', content=html)
		return render_template('page.html', content=html, title=page)
	except OSError:
		abort(404)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()

Add basic page request exception handling
Add basic page request exception handling

- from flask import Flask, render_template, url_for, Markup
+ from flask import Flask, render_template, url_for, Markup, abort
  from flask.ext.libsass import *
  import pkg_resources
  import markdown
  
  app=Flask(__name__)
  
  Sass(
  	{'app': 'scss/app.scss'},
  	app,
  	url_path='/static/css',
  	include_paths=[pkg_resources.resource_filename('views', 'scss')],
  	output_style='compressed'
  )
  
  @app.route('/<page>')
  def get_page(page):
+ 	try:
- 	md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
+ 		md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
- 	html=Markup(markdown.markdown(md.read(), output_format='html5'))
+ 		html=Markup(markdown.markdown(md.read(), output_format='html5'))
- 	md.close()
+ 		md.close()
- 	if page=='index':
+ 		if page=='index':
- 		return render_template('page.html', content=html)
+ 			return render_template('page.html', content=html)
- 	return render_template('page.html', content=html, title=page)
+ 		return render_template('page.html', content=html, title=page)
+ 	except OSError:
+ 		abort(404)
  
  @app.route('/')
  def index():
  	return get_page('index')
  
  if __name__=='__main__':
  	app.run()
  
Add basic page request exception handling
## Code Before:
from flask import Flask, render_template, url_for, Markup
from flask.ext.libsass import *
import pkg_resources
import markdown

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/<page>')
def get_page(page):
	md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
	html=Markup(markdown.markdown(md.read(), output_format='html5'))
	md.close()
	if page=='index':
		return render_template('page.html', content=html)
	return render_template('page.html', content=html, title=page)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()

## Instruction:
Add basic page request exception handling
## Code After:
from flask import Flask, render_template, url_for, Markup, abort
from flask.ext.libsass import *
import pkg_resources
import markdown

app=Flask(__name__)

Sass(
	{'app': 'scss/app.scss'},
	app,
	url_path='/static/css',
	include_paths=[pkg_resources.resource_filename('views', 'scss')],
	output_style='compressed'
)

@app.route('/<page>')
def get_page(page):
	try:
		md=open(pkg_resources.resource_filename('views', 'pages/' + page + '.md'), encoding='UTF-8')
		html=Markup(markdown.markdown(md.read(), output_format='html5'))
		md.close()
		if page=='index':
			return render_template('page.html', content=html)
		return render_template('page.html', content=html, title=page)
	except OSError:
		abort(404)

@app.route('/')
def index():
	return get_page('index')

if __name__=='__main__':
	app.run()
