Using Django with Flask


Situation:

I am preliminarily considering using Django for

  • serve HTML (according to the Django template)
  • serve all static files like CSS, JS from a Django project

and my intention to use Django stops here. After the javascript files are uploaded to the client side, they exchange data with the flag with the RESTful API (Ajax path).


Why two structures? And why so?

The third-party guy from this project I'm working with knows Django well, and I think I mostly want to use its CSS / HTML template / jquery.

I want to have an independent API server, and I feel that Flask is ideal for my need (from creating an API perspective API).

I guess people would suggest "why not ask the Django guy to use Jinga2 for templates?" (so we can end Django). I assume that my current answer will be this: I do not want it to invest too much time (to find out)

I suppose people would suggest "why not use Django to service the Restful API call?" (so we can end Flask). I assume that my current answer will be: I (as a person implementing API logic), like Flask.


My question

Short: is it doable? or does this sound like a crazy idea?

Long: can you kindly give some kind of guidance?

Thanks,

+6
source share
3 answers

If I were you, I would take the Django templates from the designer and convert them to Jinja2, and then create a 100% application in Flask. But since you asked ...

is it doable? or does this sound like a crazy idea?

Yes for both :)

Could you give some recommendations?

Here is an easy way:

You write two applications: one in Flask and one in Django. Suppose you solve all the problems that arise when trying to share a database or other resources, and now you have two applications, each of which has its own web server and each of them listens for requests on a different port.

Now you put the proxy server as your web server in the outside world and the proxy servers coming from clients to one or another application depending on the URL. You can make all the URLs for the Flask application in the format http://hostname/api/... , and then disable the api in the URL to separate requests on the proxy server and provide them to the correct application.

Since all requests go to the same host name and port (proxy server) from the outside, you will not have problems with cross-site scripts.

+4
source

I'm a little late to the party, but the Application Manager should help with this. According to the introduction to the documentation, this is so:

Application scheduling is the process of combining multiple application flasks at the WSGI level. You can not only combine the application flag into something more, but any WSGI application. This one even allows you to run the Django and Flask application in the same translator side by side if you want.

+2
source

With similar Jinja and Django templates, you really need to tell the Django developer to just use Jinja. You are going to add a lot of complexity to make this project a success.

There is no such thing as a Django developer, just a developer.

0
source

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


All Articles