Python App Development: The Step-By-Step Guide
Python language has become popular in recent years, and with good reason – it’s an easy-to-use programming language that’s also very powerful. In fact, Python is one of the top 10 most popular programming languages in the world today! If you want to learn more about this versatile language, or if you’re ready to start developing applications using Python, this article will get you on your way with a step-by-step guide to app development with Python.
Setting up the environment
Python provides a default environment that is used to run any scripts. But since this guide’s goal is to teach you how to create and run an app, we will go over the steps of setting up Python for that purpose.
Once you’ve finished downloading Python, unzip it in a location on your hard drive. Open the Command Prompt (Windows) or Terminal (Mac). Change the directory (or navigate) to the location where you unzipped python in order to access its contents by typing cd followed by a space and then inserting the path relative to your computer. Now type pip followed by a space and hit enter.
Before we install Flask, let’s take a quick look at what it can do. It helps you build web applications rapidly with a tiny framework and its vast library of extensions. It increases development efficiency by removing the need to recreate basic features from scratch for each project. What does this mean? Basically, when you use Flask, it makes it easier for developers to create websites without having to start from scratch every time.
One of the most popular Python web frameworks is Flask.
The first step is to install MySQL. You can either use the installer from the mysql site or download the .exe file and move it into your Applications folder. This tutorial will be using the installer from the mysql site, but if you downloaded the application make sure you rename it before running! To run, click ‘Install MySQL’, then click ‘Create a New Root Password’. Next, enter in your password and let’s move on to installing Python.
Creating tables in MySQL for your app
In order to store data, we need to create a database. To do this, open up your command line and type mysql to open the MySQL prompt. From there, you can execute SQL commands on the database you would like to create. Since we are creating a social media app that allows people to upload photos, let’s name our database ‘pictures’. Next, execute the following command in your MySQL terminal window: CREATE DATABASE pictures; We just created our first table in SQL!
Writing a Hello World application using Flask
Now that we have Flask installed and we know how to get the app running locally, let’s create a hello world application. In this example, we’re going to be making a Hello World message board where users can input messages and others can reply to them. So from the main screen on the browser hit New Post > enter the post title in the Title field > type a message in the Message field (just for now) > click save.
Installing and configuring Gunicorn
Gunicorn is a production web server for Python apps. Gunicorn works by having NGINX pass HTTP requests to the application server process and have that process act as an interface to the OS. First, you will need to install Gunicorn on your machine, which can be done using pip with the following command in a terminal window:
pip install gunicorn
Next, you will need to add the following lines to your code where you want the Gunicorn server called
Running your first application from your local machine
You are now set up and ready to develop your first Python application. Open up your command line, create a folder called Coding 101, and type python app.py in order to run the code for your first app. You should see something like this.