Structure a flask with an angular.js


How to structure flask app with angular.js front-end? What is best practice? Should I use webserver like ngnix to host static files even when I’m working on development?

With flask default, I can serve index.html like below:

def index():
return make_response(open('static/index.html').read())


def index():
return send_from_directory('static', 'index.html')

But, there is a problem where I cannot point js files without ‘../static’ prefix. I just want to point angular.js and all others like:

<script src="lib/angular/angular.js"></script>


<script src="../static/lib/angular/angular.js"></script>

Can I change all static file prefix in flask? Or is there a good way to solve this problem?


Problem courtesy of: ccoroom


If you really want to, you can:

app = Flask(__name__, static_url_path='')

Although I’d just use the absolute URL:


Solution courtesy of: Blender

View additional discussion.

Like what you read? Give Angular.js Recipes a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.