0

I'm new to both angular and flask framework so plz be patient with me.

I'm trying to build a web app with flask as a backend server and Angular for the frontend (I didn't start it yet), and while gathering infos and looking at tutorials and some documentation (a little bit) I'm wondering:

Does Angular server and flask server need both to be running at the same time or will just flask be enough? Knowing that I want to send data from the server to the frontend to display and collecting data from users and sending it to the backend.

I noticed some guys building the angular app and using the dist files but I don't exactly know how that works.

So can you guys suggest what should I have to do or how to proceed with this?

Thank you ^^

Joey
  • 1,436
  • 2
  • 19
  • 33
Green
  • 468
  • 5
  • 18
  • Angular is frontend of the application and flask is backend api Both are seprate things. if you run angular server then it will run backend of the application and if you run flask server then it will run backend of the application and for proper functionality of the application we need both front end and backend so it is obvious that we need to run both server at the same time to communicate with each other. :) – Samarth Saxena Mar 07 '19 at 10:18

2 Answers2

1

Angular does not need a server. It's a client-side framework so it can be served by any server like Flask. Probably in most tutorials, the backend is served by nodejs, not Flask.

maQ
  • 496
  • 3
  • 8
  • Thank you for your fast reply, so Angular app still needs to be launched with 'ng serve' even with flask app running? – Green Mar 07 '19 at 10:14
  • `ng serve` is a server but it's used for fast checking of some code without full backend needed (can be used for unit testing) to be running, but if you want to use Flask, then `ng serve` is not needed. – maQ Mar 07 '19 at 14:43
1

here is a exemple of angular and flask, by the way it works perfecty together

from angular http serverce:

  getReportPMC(X){   
    const httpOptions =  new Headers ({ 'Content-Type':"application/json" });
    return this.http.post('http://127.0.0.1:5000/predpmc',X,{headers :httpOptions}).map(response => response.json())  
  }

and from python

from flask import Flask, render_template,request 
app = Flask(__name__)
from flask_restful import  Api 
api = Api(app) 
// to allow angular to your python app
@app.after_request
def after_request(response):
  response.headers.add('Access-Control-Allow-Origin', '*')
  response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
  return response

@app.route('/hello', methods=['POST'])
def hello():
 return 'hello' 

if __name__ == '__main__':
     app.run()
asli
  • 433
  • 1
  • 5
  • 10