In the two-and-a-half years since I left being a full-stack Java developer (and even before that), I missed the new wave of web development. Now the new wave has hit my face and I’m like a kid in a candy store again. This week I tried a (not so) new Python Framework called Flask. Flask is a way of building a website from a single Python file with few lines of code – in Python. Much of Django hardly looks like Python; it’s like learning a new language. This isn’t to mean that I’ll abandon Django. But be prepared – Flask may be framework of the future and for good reason.
Django seems to be the “it” thing with Python being the popular language today. Its implementation is quite easy and its boilerplate setup has everything for an administrative-based user interface application. Anyone familiar with MVC-style web development will pick up the basics of Django in little time. The average Python coder will have few problems (for me it was the urls.py setup), but they become second-nature in time. It’s simple to set up a front end app with React, Redux, Bootstrap and whatever else you want your front end to look like. Then you can set up another app using “Serializers” for API routing. Like many new frameworks, a development web server is built in. Webpack works fine although I haven’t tried Hot Module Replacement yet. Knowing Django could be good for current employment opportunities.
On the other hand, Flask is primitive. I’m writing this after having a brief introduction, but immediately the potential for Flask was obvious. After watching several YouTube videos comparing Flask and Django, the consensus was that Flask is for Python beginners. It’s true. You can open up a Python shell and write a web page that will run from the shell. Flask has a built-in development server as well. What I found in just a few minutes of tinkering was how Python-like the code is. It would be included in a Python 101 course if I was to write one.
So the primitive way of creating a website may not be everyone’s cup of tea, but like every other language, people contribute code to do this or do that; Flask classes and functions can be added to make the server as fancy or as primitive as you like. This could then reduce the footprint of the server to what is needed. If Django features like built-in user/administrator apps aren’t needed, they’re simply not added. The bottom line is that Flask could be really appealing to the advanced Python coder who just wants the server to do exactly what he wants it to do.
Facebook’s website is a great model for others. With the trend going that way, having minimized back end web servers makes sense. Apache will probably stay, but their modules could be reduced. Tomcat and PHP could be replaced with a WSGI module and minimized Flask code can lighten the whole load. Flask uses Jinja, a template engine that looks very similar to Django’s template engine. That means that you create templates with direct calls to Jinja and it will generate the code needed for the browser to understand. Since Jinja is separate from Flask, it isn’t necessary for a website. It is there so a developer does not need to write such an engine, thankfully. On top of that, another template engine can be used. Flask is flexible.
Routing and redirection are built in so RESTful request dispatching is easy to set up. API POSTS and GETS are the best way to separate the front and back ends of a website. Discovering that a lot of API information servers line the Internet countryside has made it easy to serve information. Any source of JSON files works great and one of my plans is to convert RSS to JSON for news feeding info from more sources. None of this is new – it just shows how minimal the back end can be for a stunning and practical website.
More will be written about Flask in time, but now is a good time to learn it to be prepared for the future. Another framework may come along to replace it, but understanding what’s going on inside of the server is paramount. Custom logging and monitoring with Nagios or similar tools is doable. A plethora of Flask job opportunities may or may not happen, so don’t abandon Django, perhaps the most established of the Python frameworks. Flask is at least a good way to understand your website and experiment.
A lot of planning is going into one of my websites right now. A Python environment isn’t available for it, so React, Redux and Bootstrap will be combined with PHP to experiment and demonstrate the power of APIs and RSS newsfeeds. Getting these tasks done will help me finish my LinkedIn profile. Then I’ll hopefully become a full-stack developer again.