AngularJS setup with flask

It should be basic, but I can't get angular to play with Flask. angular and Flask have the same variable interpolation syntax {{ variable }}

and according to the blog post I can use a pipe to distinguish between the two but below it throws an error that readsno filter named 'angular'

<!DOCTYPE html>
<html ng-app>
  <head>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
    <script type="text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
  </head>
  <body>
    <label>{{ yourName | angular }}</label>
    <input type="text" ng-model="yourName" placeholder="Enter a name here">
  </body>
</html>

      

+3


source to share


3 answers


Since the "{{}}" characters are used in the AngularJS and Jinja templating system, you need to add a flask extension to deal with this problem. Use the triangle bottle extension.

Inject an instance application into the triangle constructor. Please check the code below.



app = Flask(__name__)
Triangle(app)

      

For more information go here .

+5


source


are you using render_template

HTML to submit this document? If so, the problem is that you are using Jinja2 and not Angular. Jinja2 doesn't have a filter called Angular. This can be fixed by adding a blockraw



<label>{% raw %}{{ yourname | angular }}{% endraw %}</label>

      

0


source


One option is to completely separate the Flask app and the AngularJS app. This way you won't run into interpolation problem and remove (or at least reduce) the bulb and corners connection in the application. I wrote a simple tutorial series on using Flask and AngularJS together. I think this will really help you use AngularJS and Flask together - http://tutsbucket.com/tutorials/building-a-blog-using-flask-and-angularjs-part-1/

0


source







All Articles