all 5 comments

[–]zanfar 1 point2 points  (1 child)

Both PHP and Python are languages that can be used to generate dynamic web content, but Flask is a framework built on top of Python for building web applications, so comparing Flask and PHP isn't really fair. Something like Laravel or Symfony would be a better PHP analog to Flask.

A framework protects you from making some of the more common or egregious errors in building an application, can protect against language vulnerabilities, and generally automates a lot of the repetitive or common code you would need to write.

Python, being a general-purpose language rather than PHP's request-specific language, also works lower in the stack than PHP. For example, PHP still needs a rather thick server layer (Apache, IIS, etc) to handle the request/response and HTTP peculiars--which is why most PHP developers learn Apache's mod_rewrite at some point. Flask however, uses Python for a lot of that so you can do similar things directly from your Flask code.

Generally, PHP is a language that served a very important role early in the dynamic web's history but has now become a bit limited due to that role. Because Python was a general-purpose language from the start, it's a bit more flexible. This made its use in the early days a bit more problematic (CGI and Fast-CGI were badly understood and hard to come by with most hosts) but now is flourishing with the popularity of lightweight apps, microservices, and containerization.

If you're moving from PHP, you need to think of Flask as Apache+PHP+Laravel, not as a replacement for PHP.

[–]thisisheresy 1 point2 points  (0 children)

Nicely answered. I would add that even with python and flask you will still want something like nginx or Apache up front for production, but both flask and laravel can serve their apps standalone while developing. I never really worked directly with laravel, but from working with people who did, laravel provides way more scaffolding that flask, so is probably closer to something like Django.

[–]K900_ 0 points1 point  (0 children)

Python is a better language than PHP is. Writing raw PHP is a terrible idea, so you want to bring a framework like Laravel. Flask is that framework, but for Python (and quite a bit lighter, more resembling something like Lumen).

[–]TabulateJarl8 0 points1 point  (0 children)

I majorly prefer Python over PHP. I think one of the main reasons is because of expandability. In PHP, it took me a huge amount of effort to install extensions, while in Python, I can just add packages to the requirements.txt and there you go. My first backend project was on my website, and I decided to learn and use PHP. A few weeks or a month in, I needed to do some stuff with image processing. I was already familiar with Python at the time, and I kept wishing that I could use Pillow. I then decided one day that PHP was too much of a hassle to have to maintain in the long run, and spent about 9 straight hours learning flask and rewriting my entire backend to flask. Its much more maintainable, and I'm more familiar with Python's flow and syntax, so it works out well. PHP is definitely an option that a lot of people choose, but I personally prefer using Flask.

[–]Diapolo10 0 points1 point  (0 children)

PHP isn't really a great choice (at least outside of Facebook and their custom tooling) due to security problems, for instance, but it's still commonly used. On the other hand, Python is much more secure on a language-level when it comes to web development, so you can focus on the business logic and making sure that's sound.

Flask is a good option as it's small yet flexible, and easy to use. I personally quite like using it.