How to develop a web application with angularjs on the client side and a flask on the backend?

I want to create a web application with a jar (python) on the server side and angularjs (javascript) on the client side. I checked the / flask - angular -seed project on github, but it is similar to the / angular -seed project. It does not contain flash frame support. I'm new to the flask. How to make jar and angular work together as a client server? I know how to create a web service using a jar, and also I went through an angular tutorial. But I am confused how to make these two collaborations (for example, what the http request should be called and how the bulb receives and responds to it).

+6
source share
1 answer

How I do this is to have one route for an interface (e.g. /) that will load the main html template. This template then references js for your angular application in a static folder.

Then I create routes for various points of interaction (in my case it is rest-y), of which angular also speaks. I use the angular module called restangular to make it easier / cleaner. My routes return everything in json, which can then be used directly.

I also configured and added an additional route so that / blah / everything also worked out to the main interface. I ignore the path, and as soon as angular js loads, the router (in angular) will look at the path and map it to the correct interface.

@app.route('/<path:path>') @app.route('/') def admin(path=None): return render_template('angular_interface.html') 

Basically - for the interface I completely close the flask.

EDIT: folder, you might have something like:

 __init__.py api api/__init__.py api/resources.py api/views.py static/interface/css/style.css static/interface/js/app.js static/interface/js/other_modules_etc.js static/shared/js/angular.js static/shared/js/restangular.js templates/interface.html 

In my __init__.py , I have the routing structure described above (and the Flask application app).

My interface.html template is as follows.

 <html> <head> <title>Blah</title> <link rel="stylesheet" href="{{ url_for('static', filename='interface/css/style.css') }}"/> <script src="{{ url_for('static', filename='shared/js/angular.js') }}"></script> <script src="{{ url_for('static', filename='shared/js/restangular.js') }}"></script> <script src="{{ url_for('static', filename='interface/js/app.js') }}"></script> </head> <body> {% raw %} <div ng-app="blah" ng-cloak> <div ng-controller="BlahCtrl" class="sidebar"> </div> </div> {% endraw %} </body> </html> 
+7
source

Source: https://habr.com/ru/post/954064/


All Articles