(venv)$ pip install flask # Install flask using 'pip' which is symlinked to pip2 or pip3 (no sudo needed) $ source venv/bin/activate # Activate the virual environment $ virtualenv -p python3 venv # For Python 3, or $ cd /path/to/project-directory # Choose your project directory You need to choose your own project directory and pick your Python version. We shall install Flask under a virtual environment (called myflaskvenv) under our project directory. It is strongly recommended to develop Python application under a virtual environment. Getting Started with Python-Flask Installing Flask (under a Virtual Environment) Read the Flask documentation, quick start guide, and tutorials available at the Flask mother site. Via Flask, you can handle HTTP and AJAX requests, user sessions between requests, route requests to controllers, evaluate and validate the request data, and response with HTML or JSON, and so on. Jinja2 templates (tags, filters, macros, etc).Unit test client for unit testing that facilitates write-test-first.a built-in Development Web Server and Debugger.In summary, the Flask framework provides: A popular choice is Flask-SQLAlchemy with a ORM (Object-Relational Mapper) over a relational database such as MySQL or PostgreSQL. Flask does not provide an integrated Model (M) layer, and lets you pick your database solution. Within the scope of MVC (Model-View-Controller) architecture, Werkzeug covers the Controller (C) and Jinja2 covers the View (V). High-level tasks like database access, web form and user authentication are supported through "extensions". Jinja2 ): a full-feature template engine for Python.(WSGI is a specification for simple and universal interface between web servers and Python web applications.) Werkzeug ): a WSGI (Web Server Gateway Interface) library for Python, which includes a URL routing system, fully featured request and response objects and a powerful debugger.Flask is actually a glue that sticks together two popular frameworks: It is so small to be called a micro-framework. Python-Flask Frameworkįlask ) was created by Armin Ronacher in 2000 as a small, minimalistic and light-weight Python Webapp framework. This article describe the Python's flask framework. You need to make your own decision to select a framework, which could be a hard choice. There are many Python frameworks available, e.g., full-stack frameworks like Djiango, TurboGears, web2py non-full-stack frameworks like Flask, Pyramid. Furthermore, there are just too many frameworks available and choosing the right framework turns out to be a difficult decision. On the other hand, using a framework means that you need to spend weeks or even months reading and understanding the framework, as each framework has it own "syntax" and, hence, requires a steep learning curve. Worse still, your codes are most likely messy, buggy, un-tested and un-maintainable - you can't write better codes than those who could build framework. Rolling-your-own means that you need to write ten-thousand lines of boiler-plate codes, that are already provided by a framework. To build a complex webapp, you could roll-your-own (RYO) from scratch or build it over a framework (which defines the structure and provides a set of libraries for common tasks). Miguel Grinberg, Flask Web Development, O'Reilly, 2014.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |