Issue
Situation:
I am tentatively considering a situation to use Django to
- serve HTML (by Django's template)
- serve all the static files like CSS, JS from the Django project
and my intent to use Django stops here. After the javascript files are downloaded to client side, they communicates with a Flask backend with RESTful API (the Ajax way).
Why two frameworks? And why in this way?
The frontend guy of this project I am working with knows Django very well, and I think I mainly want to use his CSS / HTML template / jquery skill.
I want to have an independent API server and I feel Flask is an ideal option for my need (from building API service perspective).
I guess people would suggest "why not ask the Django guy use Jinga2 for templating?" (in that way, we can do away with Django) I guess my current answer would be: I don't want him to invest too much time (to learn)
I guess people would suggest "why not use Django to serve the Restful API call?" (in that way, we can do away with Flask) I guess my current answer would be: I (as the person implementing API logic) like Flask.
My question
Short one: is this doable? or does this sound a crazy idea?
Long one: Can you kindly give some guidance?
Thanks,
Solution
If I were you I would take the Django templates from the designer and convert them to Jinja2, then build the application 100% in Flask. But since you asked...
is this doable? or does this sound a crazy idea?
Yes to both :)
Can you kindly give some guidance?
Here is a simple way:
You write the two applications, one in Flask and one in Django. Let's assume you solve all the problems you will have when trying to share database or other resources and now you have the two applications running, each with its own web server and each listening for requests on a different port.
You now put a proxy web server as your front web server to the outside world and proxy the requests that come from clients to one or the other application depending on the URL. You can make all the URLs for the Flask application have the format http://hostname/api/...
, and then key off of the api
in the URL to separate the requests in the proxy server and give them to the proper application.
Because from the outside all requests go to the same hostname and port (that of the proxy server) you will not have any trouble with cross-site scripting.
Answered By - Miguel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.