Breaking News

Creation of Virtual Environment -- hands on answer( Flask - Python Web Framework)frecoplay

Flask - Python Web Framework 


ntroduction to Flask
Flask is a popular Python web microframework.
Flask requires minimum setup and configuration to develop and run an app.
Flask has a strong community, providing extensions. The extensions can be used to build advanced web applications.
Flask is a BSD licensed product.
About Flask
Flask is based on the Web Server Gateway Interface toolkit, and the Jinja2 templating engine.
The Werkzeug toolkit implements requests and response objects, among other utility functions, and thus facilitates the support for building a web framework on top of it.
The Jinja2 templating engine is a popular Python web templating system that combines templates and data sources to render dynamic web pages.

Welcome to
Creation of a Python Virtual Environment

Creating a Virtual Environment
Support for creation of a virtual environment is included by default in Python version 3.4 and above.
You can create a virtual environment using venv module, while using python 3.4 and above, as shown in below command.

sudo apt-get install python3-venv
$ python3 -m venv myprojectenv


While using older versions of python, installation of the third-party module, virtualenv is required for creating a virtual environment.
After successful installation of virtualenv, you can create a virtual environment as shown below.

$ virtualenv myprojectenv

You can also run the application using flask command.
Before running flask, set and export the environment variable FLASK_APP. The two steps are shown below.

(porjenv) $ export FLASK_APP=hello.py

(projenv) $ flask run

* Serving Flask app "hello" (lazy loading)

.....

.....

.....

* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Activating a Virtual Environment
Regardless of the method, you select to create a virtual environment; the virtual environment needs to be activated before using it.
A newly created virtual environment can be activated using source command as shown below

$ source myprojectenv/bin/activate

(projenv) $ _

pip install Flask

You can exit the virtual environment simply by using deactivate command as shown below.

(projenv) $ deactivate

$ _

Features of Flask
A Development server and debugger (sanity-friendly)
Unicode support (Latin language-friendly)
WSGI compliance (uWsgi-friendly)
A unit-test client client (code with quality)
URL routing
Request dispatching
Secure cookies
Sessions
Jinja2 templates (tags, filters, macros, and more)
Managing Dependencies
Packages required for an application can be managed using pip.


The syntax for installing a package is shown below.

pip install <package_name>


Similarly, you can uninstall a package with below command.

pip uninstall <package_name>


You can also upgrade a package with below command

pip install --upgrade <package_name>

Flask - Python Web Framework





Creation of Virtual Environment -- hands on answer

to pass the hands on execute following commands one by in the terminal


$ sudo apt-get install python3-venv
$ python3 -m venv myprojectenv

$ virtualenv myprojectenv

$ source myprojectenv/bin/activate

(myprojectenv) $ pip install Flask
(myprojectenv $ deactivate

then goto run in the ide and run the test tab
completed hands on 

                    *****THE END***** 1

No comments