

{"id":15016,"date":"2018-05-12T06:31:48","date_gmt":"2018-05-12T01:01:48","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=15016"},"modified":"2026-04-28T14:53:30","modified_gmt":"2026-04-28T09:23:30","slug":"python-flask-tutorial","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/","title":{"rendered":"Learn Python Flask &#8211; A Web Framework for Python"},"content":{"rendered":"<p><span style=\"font-weight: 400\">In this Python tutorial, we will learn the basics of Python Flask. Moreover, in this Python Flask Tutorial. We will discuss a web framework for Python.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Along with this, we will learn to set up the environment, some rules, and URL building for Python Flask. At last, we will see HTTP methods in Python Flask.<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, let\u2019s begin the Python Flask tutorial.<\/span><\/p>\n<div id=\"attachment_15134\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15134\" class=\"wp-image-15134 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg\" alt=\"Learn Python Flask Tutorial - A Web Framework for Python\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-15134\" class=\"wp-caption-text\">Learn Python Flask Tutorial &#8211; A Web Framework for Python<\/p><\/div>\n<h2><span style=\"font-weight: 400\">What is Python Flask?<\/span><\/h2>\n<p><span style=\"font-weight: 400\">A micro web framework itself written in Python, Flask is BSD-license.\u00a0 <\/span><span style=\"font-weight: 400\">It was developed by Armin Ronacher, and is by Pocco- an international group of Python enthusiasts. <\/span><span style=\"font-weight: 400\">It is based on the Werkzeug toolkit and Jinja2 template engine. Now, the latest stable version is 1.0, released in April 2018. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Top applications that use it include Pinterest, LinkedIn, and the community page for Flask.<\/span><\/p>\n<div id=\"attachment_15136\" style=\"width: 3010px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15136\" class=\"wp-image-15136 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask.png\" alt=\"Python Flask\" width=\"3000\" height=\"1174\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask.png 3000w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask-150x59.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask-300x117.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask-768x301.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Flask-1024x401.png 1024w\" sizes=\"auto, (max-width: 3000px) 100vw, 3000px\" \/><\/a><p id=\"caption-attachment-15136\" class=\"wp-caption-text\">Learn Python Flask Tutorial &#8211; What is Python Flask<\/p><\/div>\n<p><span style=\"font-weight: 400\">Since it does not need any tools or libraries, we can also call it a micro-framework. <\/span><span style=\"font-weight: 400\">It also has no database abstraction layer or form validation. <\/span><span style=\"font-weight: 400\">But we can find these features as extensions. <\/span><\/p>\n<p><span style=\"font-weight: 400\">These include form validation, upload handling, object-relational mappers, open authentication technologies, and common framework tools.<\/span><\/p>\n<p><strong>Features of Flask in Python:<\/strong><\/p>\n<ul>\n<li><strong>Extremely lightweight:<\/strong> As it is a micro framework, it becomes easier for beginners to learn faster.<\/li>\n<li><strong>Flexible:<\/strong> It doesn&#8217;t force you to use any database or a folder structure.<\/li>\n<li><strong>Easy debugging:<\/strong> It shows you where the error is exactly in your web browser, making it easier to fix the error.<\/li>\n<li><strong>Huge libraries add-ons:<\/strong> If you need a creative feature like a database, you can easily add an extension created in other languages.<\/li>\n<\/ul>\n<p><strong>Here, some names around Python Flask include:<\/strong><\/p>\n<ul>\n<li><span style=\"font-weight: 400\"><strong>WSGI (Web Server Gateway Interface)<\/strong>&#8211; A standard for Python web application development.<\/span><\/li>\n<li><span style=\"font-weight: 400\"><strong>Werkzeug<\/strong>&#8211; A WSGI toolkit implementing requests, response objects, and other utility functions.<\/span><\/li>\n<li><span style=\"font-weight: 400\"><strong>Jinja 2<\/strong>&#8211; A Python templating engine.<\/span><\/li>\n<\/ul>\n<h3>Setting Up the Environment in Python Flask<\/h3>\n<p><span style=\"font-weight: 400\">Hence, to get started with Python Flask, we\u2019ll first need to set up an environment that supports it.<\/span><\/p>\n<h4>1. Prerequisites for installing Python Flask<\/h4>\n<p><span style=\"font-weight: 400\">Basically, you\u2019ll need Flask 2.6 or higher to be able to install Flask.<\/span><\/p>\n<h4>2. Install virtualenv<\/h4>\n<p><span style=\"font-weight: 400\">Next, you\u2019ll need virtualenv to build a virtual Python environment. <\/span><span style=\"font-weight: 400\">This is to create multiple environments at once to avoid compatibility issues between versions of libraries.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The command we use to install it is:<\/span><\/p>\n<p>C:\\Users\\lifei&gt;pip install virtualenv<\/p>\n<p><span style=\"font-weight: 400\">Requirement already satisfied: virtualenv in <\/span><\/p>\n<p><span style=\"font-weight: 400\">c:\\users\\lifei\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages (15.1.0)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Since we already have it installed, it states so.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, create a new environment in a new folder:<\/span><\/p>\n<p>C:\\Users\\lifei&gt;cd Desktop<\/p>\n<p>C:\\Users\\lifei\\Desktop&gt;mkdir projectx<\/p>\n<p>C:\\Users\\lifei\\Desktop&gt;cd projectx<\/p>\n<p>C:\\Users\\lifei\\Desktop\\projectx&gt;virtualenv venv<\/p>\n<p>Using base prefix &#8216;c:\\\\users\\\\lifei\\\\appdata\\\\local\\\\programs\\\\python\\\\python36-32&#8217;<\/p>\n<p>New python executable in C:\\Users\\lifei\\Desktop\\projectx\\venv\\Scripts\\python.exe<\/p>\n<p>Installing setuptools, pip, wheel&#8230;done.<\/p>\n<p>C:\\Users\\lifei\\Desktop\\projectx&gt;<\/p>\n<p>Then activate the corresponding environment:<\/p>\n<p>C:\\Users\\lifei\\Desktop\\projectx&gt;venv\\scripts\\activate<\/p>\n<p>(venv) C:\\Users\\lifei\\Desktop\\projectx&gt;<\/p>\n<p><span style=\"font-weight: 400\">Finally, install Flask (You don\u2019t necessarily have to be in the virtual environment for this):<\/span><br \/>\n<span style=\"font-weight: 400\">(venv) C:\\Users\\lifei\\Desktop\\projectx&gt;pip install flask<\/span><br \/>\n<span style=\"font-weight: 400\">Collecting flask<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/55\/b1\/4365193655df97227ace49311365cc296e74b60c7f5c63d23cd30175e2f6\/Flask-1.0-py2.py3-none-any.whl (97kB)<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0100% |<\/span><span style=\"font-weight: 400\">\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/span><span style=\"font-weight: 400\">| 102kB 143kB\/s<\/span><\/p>\n<p><span style=\"font-weight: 400\">Collecting itsdangerous&gt;=0.24 (from flask)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/dc\/b4\/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4\/itsdangerous-0.24.tar.gz (46kB)<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0100% |<\/span><span style=\"font-weight: 400\">\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/span><span style=\"font-weight: 400\">| 51kB 67kB\/s<\/span><\/p>\n<p><span style=\"font-weight: 400\">Collecting Jinja2&gt;=2.10 (from flask)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/7f\/ff\/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731\/Jinja2-2.10-py2.py3-none-any.whl (126kB)<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0100% |<\/span><span style=\"font-weight: 400\">\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/span><span style=\"font-weight: 400\">| 133kB 33kB\/s<\/span><\/p>\n<p><span style=\"font-weight: 400\">Collecting click&gt;=5.1 (from flask)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/34\/c1\/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77\/click-6.7-py2.py3-none-any.whl (71kB)<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0100% |<\/span><span style=\"font-weight: 400\">\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/span><span style=\"font-weight: 400\">| 71kB 36kB\/s<\/span><\/p>\n<p><span style=\"font-weight: 400\">Collecting Werkzeug&gt;=0.14 (from flask)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/20\/c4\/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243\/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0\u00a0\u00a0100% |<\/span><span style=\"font-weight: 400\">\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588<\/span><span style=\"font-weight: 400\">| 327kB 33kB\/s<\/span><\/p>\n<p><span style=\"font-weight: 400\">Collecting MarkupSafe&gt;=0.23 (from Jinja2&gt;=2.10-&gt;flask)<\/span><\/p>\n<p><span style=\"font-weight: 400\">Downloading <\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>https:\/\/files.pythonhosted.org\/packages\/4d\/de\/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b\/MarkupSafe-1.0.tar.gz<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">Building wheels for collected packages: itsdangerous, MarkupSafe<\/span><\/p>\n<p><span style=\"font-weight: 400\">Running setup.py bdist_wheel for itsdangerous &#8230; done<\/span><\/p>\n<p><span style=\"font-weight: 400\">\u00a0Stored in directory: <\/span><\/p>\n<p><strong>C:\\Users\\lifei\\AppData\\Local\\pip\\Cache\\wheels\\2c\\4a\\61\\5599631c1554768c6290b08c02c72d7317910374ca602ff1e5<\/strong><\/p>\n<p><span style=\"font-weight: 400\">Running setup.py bdist_wheel for MarkupSafe &#8230; done<\/span><\/p>\n<p>Stored in directory:<\/p>\n<p><strong>C:\\Users\\lifei\\AppData\\Local\\pip\\Cache\\wheels\\33\\56\\20\\ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46<\/strong><\/p>\n<p><span style=\"font-weight: 400\">Successfully built its dangerous MarkupSafe<\/span><\/p>\n<p><span style=\"font-weight: 400\">Installing collected packages: itsdangerous, MarkupSafe, Jinja2, click, Werkzeug, flask\u00a0<\/span><span style=\"font-weight: 400\">Successfully installed Jinja2-2.10 MarkupSafe-1.0 Werkzeug-0.14.1 click-6.7 flask-1.0 itsdangerous-0.24<\/span><\/p>\n<p><span style=\"font-weight: 400\">(venv) C:\\Users\\lifei\\Desktop\\projectx&gt;<\/span><\/p>\n<h3>Beginning with Python Flask<\/h3>\n<p><span style=\"font-weight: 400\">Now, in the Python Flask tutorial, let\u2019s begin with a program that says Hello.<\/span><br \/>\n<span style=\"font-weight: 400\">from flask import Flask<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask\r\n&gt;&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/')\r\ndef sayhello():\r\n       return 'Hello'\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app.debug=True\r\n       app.run()<\/pre>\n<p><span style=\"font-weight: 400\">We save this as demo.py in the project folder. Then, we get to the command prompt to run this.<\/span><\/p>\n<p>C:\\Users\\lifei&gt;cd Desktop\/projectx<\/p>\n<p>C:\\Users\\lifei\\Desktop\\projectx&gt;python demo.py<\/p>\n<p>* Serving Flask app &#8220;demo&#8221; (lazy loading)<\/p>\n<p>* Environment: production<\/p>\n<p>WARNING: Do not use the development server in a production environment.<\/p>\n<p>Use a production WSGI server instead.<\/p>\n<p>* Debug mode: on<\/p>\n<p>* Restarting with stat<\/p>\n<p>* Debugger is active!<\/p>\n<p>* Debugger PIN: 174-045-654<\/p>\n<p>* Running on http:\/\/127.0.0.1:5000\/ (Press CTRL+C to quit)<\/p>\n<p>127.0.0.1 &#8211; &#8211; [29\/Apr\/2018 15:00:03] &#8220;GET \/ HTTP\/1.1&#8221; 200 &#8211;<\/p>\n<p>127.0.0.1 &#8211; &#8211; [29\/Apr\/2018 15:00:04] &#8220;GET \/favicon.ico HTTP\/1.1&#8221; 404 \u2013<\/p>\n<p><span style=\"font-weight: 400\">From here, we take the address 127.0.0.1:5000 and paste it into the address bar of our browser:<\/span><\/p>\n<div id=\"attachment_15138\" style=\"width: 1612px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15138\" class=\"wp-image-15138 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello.png\" alt=\"Learn Python Flask Tutorial \" width=\"1602\" height=\"778\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello.png 1602w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello-150x73.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello-300x146.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello-768x373.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/hello-1024x497.png 1024w\" sizes=\"auto, (max-width: 1602px) 100vw, 1602px\" \/><\/a><p id=\"caption-attachment-15138\" class=\"wp-caption-text\">Python Flask Tutorial &#8211;\u00a0<span style=\"font-weight: 400\">Beginning with Python Flask<\/span><\/p><\/div>\n<p><span style=\"font-weight: 400\">Here, the Flask() constructor takes an argument, the current module\u2019s name: __name__.<\/span><\/p>\n<p><span style=\"font-weight: 400\">route() is a decorator function that decides which URL to allow to call the associated function. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Its syntax is:<\/span><\/p>\n<p><strong>app.route(rule,options)<\/strong><\/p>\n<p><span style=\"font-weight: 400\">While the <\/span><i><span style=\"font-weight: 400\">rule<\/span><\/i><span style=\"font-weight: 400\"> denotes the URL binding with the function, <\/span><i><span style=\"font-weight: 400\">options<\/span><\/i><span style=\"font-weight: 400\"> hold parameters to be forwarded to this <\/span><i><span style=\"font-weight: 400\">rule<\/span><\/i><span style=\"font-weight: 400\"> object. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Here, we bind the URL \u2018\/\u2019 to the function sayhello(). So, getting to where that URL point takes us to where this function executes. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Take a look at this code:<\/span><\/p>\n<p><span style=\"font-weight: 400\">From flask import Flask<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask\r\n&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/')\r\ndef sayhello():\r\n      return 'Hello'\r\n&gt;&gt;&gt; @app.route('\/hi')\r\ndef sayhi():\r\n       return 'Hi'\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app.debug=True\r\n       app.run()<\/pre>\n<p>When we go to the following URL:<\/p>\n<p><strong>http:\/\/127.0.0.1:5000\/hi<\/strong><\/p>\n<p><span style=\"font-weight: 400\">The browser displays:<\/span><\/p>\n<p><span style=\"font-weight: 400\">Hi<\/span><\/p>\n<p><span style=\"font-weight: 400\">So, you can see all this activity on your command prompt side by side. <\/span><\/p>\n<p><span style=\"font-weight: 400\">We can also use the app.add_url_rule() function for this:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; def salut():\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return 'Buna'\r\n&gt;&gt;&gt; app.add_url_rule('\/salut','buna',salut)<\/pre>\n<div id=\"attachment_15139\" style=\"width: 721px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/add_url_rule.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15139\" class=\"wp-image-15139 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/add_url_rule.png\" alt=\"Python Flask Tutorial\" width=\"711\" height=\"229\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/add_url_rule.png 711w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/add_url_rule-150x48.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/add_url_rule-300x97.png 300w\" sizes=\"auto, (max-width: 711px) 100vw, 711px\" \/><\/a><p id=\"caption-attachment-15139\" class=\"wp-caption-text\">Python Flask Tutorial &#8211;\u00a0<span style=\"font-weight: 400\">Beginning with Python Flask<\/span><\/p><\/div>\n<p><span style=\"font-weight: 400\">Now, when we set debug to True, the server automatically reloads on changes to the code. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Otherwise, we\u2019d have to restart it manually for each change.<\/span><\/p>\n<p><span style=\"font-weight: 400\">And finally, the method run() runs the application on the local development server. This may take up to four arguments:<\/span><\/p>\n<p><strong>run(host, port, debug, options)<\/strong><\/p>\n<p><span style=\"font-weight: 400\">The default hostname to listen to is 127.0.0.1 (the localhost); we can set it to 0.0.0.0 to avail a server externally. <\/span><\/p>\n<p><span style=\"font-weight: 400\">The default port is 5000. debug is false by default, and we can forward the <\/span><i><span style=\"font-weight: 400\">options<\/span><\/i><span style=\"font-weight: 400\"> to the underlying Werkzeug server.<\/span><\/p>\n<h3>Variable Rules in Python Flask<\/h3>\n<p><span style=\"font-weight: 400\">It is also possible to dynamically build a URL. <\/span><\/p>\n<p><span style=\"font-weight: 400\">We put the variable parts in angular brackets in the rule, and pass them as parameters to the associated function:<\/span><\/p>\n<p><span style=\"font-weight: 400\">From flask import Flask<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask\r\n&gt;&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/')\r\ndef sayhello():\r\n    return 'Hello'\r\n&gt;&gt;&gt; @app.route('\/&lt;one&gt;add&lt;two&gt;')\r\ndef add(one,two):\r\n    return f\"{one}+{two}={int(one)+int(two)}\"\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n    app.debug=True\r\n    app.run()<\/pre>\n<p><span style=\"font-weight: 400\">And in the browser:<\/span><\/p>\n<div id=\"attachment_15140\" style=\"width: 657px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/2add3.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15140\" class=\"wp-image-15140 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/2add3.png\" alt=\" Python Flask Tutorial - Variable Rules in Python Flask\" width=\"647\" height=\"221\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/2add3.png 647w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/2add3-150x51.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/2add3-300x102.png 300w\" sizes=\"auto, (max-width: 647px) 100vw, 647px\" \/><\/a><p id=\"caption-attachment-15140\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; Variable Rules in Python Flask<\/p><\/div>\n<p><span style=\"font-weight: 400\">And another one:<\/span><\/p>\n<div id=\"attachment_15141\" style=\"width: 603px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/1add-7.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15141\" class=\"wp-image-15141 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/1add-7.png\" alt=\" Python Flask Tutorial - Variable Rules in Python Flask\" width=\"593\" height=\"207\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/1add-7.png 593w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/1add-7-150x52.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/1add-7-300x105.png 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/a><p id=\"caption-attachment-15141\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; Variable Rules in Python Flask<\/p><\/div>\n<p><span style=\"font-weight: 400\">So, we can also use the following converters- int, float, path:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; @app.route('\/&lt;int:one&gt;add&lt;int:two&gt;')\r\ndef add(one,two):\r\n       return f\"{one}+{two}={one+two}\"\r\n&gt;&gt;&gt; @app.route('\/&lt;float:one&gt;add&lt;float:two&gt;')\r\ndef add(one,two):\r\n       return f\"{one}+{two}={one+two}\"<\/pre>\n<div id=\"attachment_15142\" style=\"width: 667px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/float.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15142\" class=\"wp-image-15142 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/float.png\" alt=\" Python Flask Tutorial - Variable Rules in Python Flask\" width=\"657\" height=\"225\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/float.png 657w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/float-150x51.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/float-300x103.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/a><p id=\"caption-attachment-15142\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; Variable Rules in Python Flask<\/p><\/div>\n<p><span style=\"font-weight: 400\">Werkzeug\u2019s routing model ensures the uniqueness of these URLs, and also that they maintain the standards laid by Apache.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Ending a rule with a trailing slash will make it work with and without it. But not doing so, it won\u2019t work with a trailing slash.<\/span><\/p>\n<p><span style=\"font-weight: 400\">From flask import Flask<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask\r\n&gt;&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/')\r\ndef sayhello():\r\n      return 'Hello'\r\n&gt;&gt;&gt; @app.route('\/hi\/')\r\ndef sayhi():\r\n       return 'Hi'\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app.debug=True\r\n       app.run()<\/pre>\n<p><span style=\"font-weight: 400\">If we remove the trailing slash, the snippet of code remains:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; @app.route('\/hi')\r\ndef sayhi():\u00a0 \u00a0 \u00a0return 'Hi'<\/pre>\n<p><span style=\"font-weight: 400\">And this happens:<\/span><\/p>\n<div id=\"attachment_15143\" style=\"width: 1255px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15143\" class=\"wp-image-15143 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404.png\" alt=\" Python Flask Tutorial - Variable Rules in Python Flask\" width=\"1245\" height=\"318\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404.png 1245w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404-150x38.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404-300x77.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404-768x196.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/404-1024x262.png 1024w\" sizes=\"auto, (max-width: 1245px) 100vw, 1245px\" \/><\/a><p id=\"caption-attachment-15143\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; Variable Rules in Python Flask<\/p><\/div>\n<h3>URL Building for Python Flask<\/h3>\n<p><span style=\"font-weight: 400\">To dynamically build a URL according to need, we use two functions: redirect() and url_for(). <\/span><\/p>\n<p><span style=\"font-weight: 400\">We need to import these as well.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask, url_for,redirect\r\n&gt;&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/')\r\ndef sayhello():\r\n               return 'Hello'\r\n&gt;&gt;&gt; @app.route('\/&lt;name&gt;')\r\ndef sayhi(name):\r\n               return f'Hi, {name}'\r\n&gt;&gt;&gt; @app.route('\/panel\/&lt;salutation&gt;')\r\ndef saysomething(salutation):\r\n       if salutation=='guest':\r\n               return redirect(url_for('sayhello'))\r\n       else:\r\n               return redirect(url_for('sayhi',name=salutation))\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app.debug=True\r\n       app.run()<\/pre>\n<p><span style=\"font-weight: 400\">The function saysomething() takes a salutation as an argument. If this is a \u2018guest\u2019, it executes the function sayhello() and prints Hello. <\/span><\/p>\n<p><span style=\"font-weight: 400\">If this is anything else, it prints hi to that string. For instance, getting to 127.0.0.1:5000\/panel\/ayushi takes us to 127.0.0.1:5000\/ayushi and prints this:<\/span><\/p>\n<p><span style=\"font-weight: 400\">Hi, ayushi.<\/span><\/p>\n<h3>HTTP Methods in Python Flask<\/h3>\n<p><span style=\"font-weight: 400\">Now, we discuss different HTTP methods to retrieve data from a URL.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>1. GET:<\/strong>\u00a0<\/span><span style=\"font-weight: 400\">The GET method sends data to the server unencrypted.<\/span><\/p>\n<p><strong>2. HEAD: <\/strong><span style=\"font-weight: 400\">HEAD is like GET, except that it has no response body.<\/span><\/p>\n<p><strong>3. POST: <\/strong><span style=\"font-weight: 400\">The server does not cache the HTML form data that this sends.<\/span><\/p>\n<p><strong>4. PUT: <\/strong><span style=\"font-weight: 400\">This uses the uploaded content to replace current representations of the target resource.<\/span><\/p>\n<p><strong>5. DELETE: <\/strong><span style=\"font-weight: 400\">This removes current representations of the target resource suggested by a URL.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Basically, the default route takes GET requests, but we can alter this by using the route() decorator with a method&#8217;s argument.<\/span><\/p>\n<p><span style=\"font-weight: 400\">Now, take the following Python code:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; from flask import Flask,url_for,redirect, request\r\n&gt;&gt;&gt; app=Flask(__name__)\r\n&gt;&gt;&gt; @app.route('\/success\/&lt;name&gt;')\r\ndef success(name):\r\n              return f'Hello, {name}'\r\n&gt;&gt;&gt; @app.route('\/login',methods=['POST','GET'])\r\ndef login():\r\n       if request.method=='POST':\r\n               user=request.form['firstname']\r\n               return redirect(url_for('success',name=user))\r\n       else:\r\n               user=request.args.get('firstname')\r\n               return redirect(url_for('success',name=user))\r\n&gt;&gt;&gt; if __name__=='__main__':\r\n       app.debug=True\r\n       app.run()<\/pre>\n<p>And this is the form we have:<\/p>\n<p>&lt;head&gt;&lt;\/head&gt;<\/p>\n<p>&lt;body&gt;<\/p>\n<p>&lt;form action = &#8220;http:\/\/localhost:5000\/login&#8221; method = &#8220;post&#8221;&gt;<\/p>\n<p>&lt;input type=&#8221;text&#8221; name=&#8221;firstname&#8221;\/&gt;&lt;br\/&gt;<\/p>\n<p>&lt;input type=&#8221;submit&#8221; value=&#8221;submit&#8221;\/&gt; &lt;\/form&gt;<\/p>\n<p>&lt;\/body&gt;<\/p>\n<p><span style=\"font-weight: 400\">When you open this HTML page in the browser:<\/span><\/p>\n<div id=\"attachment_15144\" style=\"width: 869px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15144\" class=\"wp-image-15144 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get.png\" alt=\"Python Flask Tutorial\" width=\"859\" height=\"341\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get.png 859w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get-150x60.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get-300x119.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get-768x305.png 768w\" sizes=\"auto, (max-width: 859px) 100vw, 859px\" \/><\/a><p id=\"caption-attachment-15144\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; HTTP Methods<\/p><\/div>\n<div id=\"attachment_15145\" style=\"width: 839px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15145\" class=\"wp-image-15145 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1.png\" alt=\"Python Flask Tutorial\" width=\"829\" height=\"229\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1.png 829w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1-150x41.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1-300x83.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get1-768x212.png 768w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/a><p id=\"caption-attachment-15145\" class=\"wp-caption-text\">Python Flask Tutorial &#8211; HTTP Methods<\/p><\/div>\n<div id=\"attachment_15146\" style=\"width: 635px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get2.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-15146\" class=\"wp-image-15146 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get2.png\" alt=\"Python Flask Tutorial\" width=\"625\" height=\"231\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get2.png 625w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get2-150x55.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/get2-300x111.png 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><p id=\"caption-attachment-15146\" class=\"wp-caption-text\">Learn Python Flask Tutorial &#8211; HTTP METHODS<\/p><\/div>\n<p>So, this was all about the Python Flask tutorial. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on Flask Framework<\/h3>\n<ol>\n<li>What is Python Flask good for?<\/li>\n<li>What are the features of Python Flask?<\/li>\n<li>Is Python Flask a frontend or a backend?<\/li>\n<li>How does Flask work in Python?<\/li>\n<li>Which is better, Flask or Django in Python? Explain with reason.<\/li>\n<\/ol>\n<h3><span style=\"font-weight: 400\">Conclusion<\/span><\/h3>\n<p><span style=\"font-weight: 400\">Hence, this is just a brief introduction to get you started with Python Flask. <\/span><span style=\"font-weight: 400\">Here, we studied the basics of Python Flask, setting up the environment for Flask. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Moreover, we studied how to begin with Python Flask and its variable rules. Along with this, we saw how to build a URL for Python Flask. <\/span><\/p>\n<p><span style=\"font-weight: 400\">At last, we discussed how to retrieve data from a URL using HTTP methods.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python tutorial, we will learn the basics of Python Flask. Moreover, in this Python Flask Tutorial. We will discuss a web framework for Python.\u00a0 Along with this, we will learn to set&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":15134,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[4388,4730,4731,4732,6414,7785,10540,10541,15182],"class_list":["post-15016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-examples-of-flask","tag-flask","tag-flask-download","tag-flask-example","tag-http-methods-in-flask","tag-jinja","tag-python-flask","tag-python-flask-tutorial","tag-url-building-for-flask"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Learn Python Flask - A Web Framework for Python - DataFlair<\/title>\n<meta name=\"description\" content=\"A Flask is a micro web framework written in Python. Let&#039;s get started with Python Flask&#039;s basics, environment setup, and much more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn Python Flask - A Web Framework for Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"A Flask is a micro web framework written in Python. Let&#039;s get started with Python Flask&#039;s basics, environment setup, and much more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-05-12T01:01:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-28T09:23:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn Python Flask - A Web Framework for Python - DataFlair","description":"A Flask is a micro web framework written in Python. Let's get started with Python Flask's basics, environment setup, and much more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Learn Python Flask - A Web Framework for Python - DataFlair","og_description":"A Flask is a micro web framework written in Python. Let's get started with Python Flask's basics, environment setup, and much more.","og_url":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-05-12T01:01:48+00:00","article_modified_time":"2026-04-28T09:23:30+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Learn Python Flask &#8211; A Web Framework for Python","datePublished":"2018-05-12T01:01:48+00:00","dateModified":"2026-04-28T09:23:30+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/"},"wordCount":1839,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg","keywords":["Examples of flask","flask","Flask download","flask example","HTTP methods in flask","JInja","Python Flask","Python Flask tutorial","URL building for Flask"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/","url":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/","name":"Learn Python Flask - A Web Framework for Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg","datePublished":"2018-05-12T01:01:48+00:00","dateModified":"2026-04-28T09:23:30+00:00","description":"A Flask is a micro web framework written in Python. Let's get started with Python Flask's basics, environment setup, and much more.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/05\/Python-Flask-Framework.jpg","width":1200,"height":628,"caption":"Python Flask"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-flask-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Learn Python Flask &#8211; A Web Framework for Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=15016"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15016\/revisions"}],"predecessor-version":[{"id":148017,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/15016\/revisions\/148017"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/15134"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=15016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=15016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=15016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}