How To Use Python Flask To Build A Website Using Eclipse On Windows Tutorial On Youtube
How to prepare upwardly your Python and Flask evolution environment
In this guide, we'll cover how to set up your Python development environment for a Flask project. We'll employ virtual environments to isolate our dependencies, and pip for parcel management. Also, we'll talk nearly a couple of helpful tools that we recommend for prototyping Python applications that use Twilio: ngrok and the Twilio Python SDK.
Let's get started!
Cull a Python version
There are 2 different versions of Python in widespread utilise today: Python 2 and Python 3. If you're new to Python, choosing the right version for your project tin can be disruptive.
Python iii was beginning released in 2008, simply some parts of the Python community continue to adopt Python 2 for various reasons. You can read more about the history of Python two vs. Python 3 here.
Twilio's Python server-side SDK supports Python versions 3.half-dozen+.
# Check your Python version $ python --version Python iii.7.0 If Python is already installed on your system, you can check its version by running python --version.
Install Python
How yous install Python varies depending on your operating organisation.
Install a text editor or IDE
Before we can start our Python projection, we'll need something to write it with.
If you already have a code writing tool of choice, you can stick with it for developing your Python application. If you lot're looking for something new, we recommend trying out a few options:
- Sublime Text is a text editor pop for its ease of use and extensibility. Start here if you're eager to get coding and don't recall you lot'll want a lot of frills in your evolution environment.
- Visual Studio Code is another text editor that'south gratis, easy to set up, and available on all platforms.
- PyCharm is a full Integrated Development Environment (IDE) for Python. It takes longer to set up simply comes with more than helpful tools already installed.
- Python Tools for Visual Studio is a cracking selection if you're already a Visual Studio user.
- Vim is a perennial favorite text editor among advanced users
If you're new to programming, nosotros recommend giving Sublime Text and PyCharm each a try before you settle on your favorite.
Start a new projection with virtualenv
Before starting whatsoever new Python project, we should create a virtual surround for it.
Virtual environments (shortened as "virtualenv") separate our new project'south Python dependencies from our other projects and from the Python libraries our operating system uses. If yous don't use a virtualenv, there'southward a skillful chance you might break part of your OS.
If you accept Python 3.3 or above you lot don't demand to install annihilation – the standard library provides virtualenv under the module "venv".
If you lot accept an older version, you'll demand to install this Python utility which allows you to create and manage Python virtual environments. Utilise the virtualenv command to create a new virtual environment, using its sole argument to proper noun your new environment. The instructions to activate your new virtualenv vary by operating system:
# Create a new virtualenv named "myproject" # Python 3.3+ $ python -m venv myproject # Python pre 3.3 $ virtualenv myproject New python executable in myproject/bin/python Installing setuptools, pip, wheel...done. # Actuate the virtualenv (OS 10 & Linux) $ source myproject/bin/activate # Actuate the virtualenv (Windows) $ myproject\Scripts\activate Yous'll need to activate your virtual environment every time y'all piece of work on your Python projection. In the rare cases when y'all want to deactivate your virtualenv without closing your terminal session, simply apply the deactivate command.
Install Flask and the Twilio Python SDK
We're virtually fix to start writing our Flask spider web awarding, but get-go we demand to install the Flask library in our virtual surround.
# Utilize pip to install the Flask and twilio libraries $ pip install Flask twilio Collecting Flask Using buried Flask-0.11.i-py2.py3-none-any.whl Collecting twilio Collecting click>=2.0 (from Flask) Collecting itsdangerous>=0.21 (from Flask) Collecting Werkzeug>=0.7 (from Flask) Using buried Werkzeug-0.xi.11-py2.py3-none-any.whl Collecting Jinja2>=ii.4 (from Flask) Using cached Jinja2-two.viii-py2.py3-none-any.whl Collecting pytz (from twilio) Using cached pytz-2016.7-py2.py3-none-any.whl Collecting half-dozen (from twilio) Using buried six-ane.x.0-py2.py3-none-whatsoever.whl Collecting httplib2>=0.vii (from twilio) Collecting MarkupSafe (from Jinja2>=2.4->Flask) Installing nerveless packages: click, itsdangerous, Werkzeug, MarkupSafe, Jinja2, Flask, pytz, half-dozen, httplib2, twilio Successfully installed Flask-0.xi.ane Jinja2-2.viii MarkupSafe-0.23 Werkzeug-0.eleven.11 click-half-dozen.half dozen httplib2-0.ix.ii itsdangerous-0.24 pytz-2016.7 six-1.10.0 twilio-5.vi.0 Python uses pip to manage dependencies, so the command to pull Flask and the Twilio SDK into our development environment is pip install Flask twilio.
Afterward yous go your dependencies installed and ostend they're doing the fox for you, you lot'll probably want to keep track of and command what versions of the dependencies you're using. Pip allows united states to "freeze" our dependencies, and tape which versions we are using in a file that (by convention) is called requirements.txt. Create a requirements file with this control:
pip freeze > requirements.txt If later on, you wish to install this aforementioned set up of dependencies once more, you tin install them from this file with the following command:
pip install -r requirements.txt Create a simple Flask application
We can test that our development environment is configured correctly past creating a simple Flask awarding. Nosotros'll grab the nine-line case from Flask'due south homepage and drop it in a new file called app.py.
from flask import Flask app = Flask(__name__) @app.road("/") def how-do-you-do(): return "Hello Earth!" if __name__ == "__main__": app.run() We tin then try running our new Flask awarding with the command python app.py. You can then open up http://localhost:5000 in your browser, and you should see the "Howdy Earth!" response.
Note: If you're using a virtual machine for your evolution surroundings, like vagrant, you might not exist able to see your Flask application at the localhost host name. Continue on to the ngrok section for an easy manner to set up this.
The Django Culling
While Flask is a micro-framework that can exist extended with various libraries, Django is another popular spider web framework that provides a lot more out of the box. If yous're interested in using Django, nosotros recommend following their guides to go started with information technology.
Install ngrok
Once you meet your sample Flask application's "Hello Earth!" message, your development environment is prepare to go. But for near Twilio projects you'll want to install i more than helpful tool: ngrok.
About Twilio services use webhooks to communicate with your application. When Twilio receives an incoming telephone phone call, for case, it reaches out to a URL in your application for instructions on how to handle the call.
When you're working on your Flask awarding in your development environs, your app is only reachable by other programs on the same calculator, so Twilio won't be able to talk to information technology.
Ngrok is our favorite tool for solving this problem. Once started, information technology provides a unique URL on the ngrok.io domain which will forward incoming requests to your local evolution surroundings.
To get-go, head over to the Ngrok download page and take hold of the binary for your operating organization: https://ngrok.com/download
One time downloaded, make sure your Flask application is running and then kickoff Ngrok using this control: "./ngrok http 5000". Y'all should see output similar to this:
Await at the "Forwarding" line to encounter your unique Ngrok domain proper name (ours is "aaf29606.ngrok.io") and and then point your browser at that domain name.
If everything'south working correctly, you lot should see your Flask application'south "Hullo World!" message displayed at your new Ngrok URL.
Someday you're working on your Twilio application and need a URL for a webhook you lot should use Ngrok to go a publicly accessible URL similar this one.
Where to next?
Nicely done! Yous've learned nearly ngrok, pip and virtual environments, and you lot're at present prepare to build out your Flask awarding.
Gear up to build something more substantiate with Twilio? Here are a few other resources we like:
Twilio
Flask
Django
Source: https://www.twilio.com/docs/usage/tutorials/how-to-set-up-your-python-and-flask-development-environment
Posted by: blanknothad1946.blogspot.com

0 Response to "How To Use Python Flask To Build A Website Using Eclipse On Windows Tutorial On Youtube"
Post a Comment