I have three files in my python flask application built on angular js for front end.
app.py
import json
import flask
import numpy as np
app = flask.Flask(__name__)
@app.route("/")
def index():
return flask.render_template("index.html")
if __name__ == "__main__":
import os
port = 80
# Open a web browser pointing at the app.
os.system("open http://localhost:{0}".format(port))
# Set up the development server on port 80.
app.debug = True
app.run(port=port)
index.html
<!DOCTYPE html>
<html ng-app="gemStore">
<head>
<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js'></script>
<script type="text/javascript" src="static/app.js"></script>
</head>
<body ng-controller="StoreController as store">
<div class="list-group-item">
<h3>{{store.product.name}} <em class="pull-right">25</em></h3>
</div>
</body>
</html>
app.js
(function() {
var app = angular.module('gemStore', []);
app.controller('StoreController', function(){
this.product = gem;
}
);
var gem = {
name: "Chicken",
price: 123.11,
color: "White"
};
})();
When I run this application, the presence of the following line causes an error:
<h3>{{store.product.name}} <em class="pull-right">25</em></h3>
I get an error saying. jinja2.exceptions.UndefinedError UndefinedError: 'store' is undefined
This is strange because the same front end application would run properly if I didn't use a python flask server. Also, I checked the html file is correctly referencing the app.js file by testing an alert.