I face a function undefined error when I run the server (FLASK app):
NameError: name 'format_date' is not defined

This is all my code so far:
from flask import Flask, render_template
import markdown
import os
from werkzeug import cached_property
import yaml
POSTS_FILE_EXTENSION = '.md'
app = Flask(__name__)
class Post(object):
def __init__(self,path):
self.path=path
self._initialize_metadata()
@cached_property
def html(self):
with open(self.path, 'r') as fin:
content= fin.read().split('\n\n',1)[1].strip()
return markdown.markdown(content)
def _initialize_metadata(self):
content = ''
with open(self.path, 'r') as fin:
for line in fin:
if not line.strip():
break
content +=line
self.__dict__.update(yaml.load(content))
def format_date(value, format='%B %d, %Y'):
return value.strftime(format)
@app.route('/')
def index():
return 'Hello, world!'
@app.route('/blog/<path:path>')
def post(path):
#import ipdb; ipdb.set_trace()
path = os.path.join('posts', path+'.md')
post = Post(path)
return render_template('post.html', post=post, format_date=format_date)
if __name__ == '__main__':
app.run(port=8000, debug=True)
Why does it say undefined? I defined it. :|
post.html:
<h3 id='date'>{{format_date(post.date)}}</h3>
hello.md:
title: Hello, worldtitle!
date: 2013-03-25
# Hello WOrld
### This is an H3 level header
P.S. : Don't judge me, I'm a noob.
render_templateline, because you have the function defined in another file, not the one that contains yourpostfunctionformat_datedoes not exist.Post.format_dateexists - as a method defined in class. In Python indentation is crucial - it's part of a syntax. Please fix it.