<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pro-Tek Blog &#187; Python’s Flask</title>
	<atom:link href="http://www.pro-tekconsulting.com/blog/tag/pythons-flask/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pro-tekconsulting.com/blog</link>
	<description>For UI developers / UI designers and UI trends</description>
	<lastBuildDate>Thu, 05 Sep 2019 03:59:47 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.0.34</generator>
	<item>
		<title>PYTHON’S FLASK</title>
		<link>http://www.pro-tekconsulting.com/blog/pythons-flask/</link>
		<comments>http://www.pro-tekconsulting.com/blog/pythons-flask/#comments</comments>
		<pubDate>Wed, 31 Oct 2018 02:17:47 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PYTHON]]></category>
		<category><![CDATA[Python’s Flask]]></category>

		<guid isPermaLink="false">http://www.pro-tekconsulting.com/blog/?p=2714</guid>
		<description><![CDATA[<p>Python’s Flask Flask is a small and powerful web framework for Python. It is easy to learn and simple to use, enabling the users to build their web app in less amount of time. Flask is also easy to get started with as a beginner because there is little boilerplate code for getting a simple [&#8230;]</p>
<p>The post <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog/pythons-flask/">PYTHON’S FLASK</a> appeared first on <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog">Pro-Tek Blog</a>.</p>
]]></description>
				<content:encoded><![CDATA[<h4>Python’s Flask</h4>
<p><img class="aligncenter wp-image-2726" src="http://www.pro-tekconsulting.com/blog/wp-content/uploads/2018/10/Python_Flask-300x271.jpg" alt="Python_Flask" width="250" height="226" /><br />
Flask is a small and powerful web framework for Python. It is easy to learn and simple to use, enabling the users to build their web app in less amount of time. Flask is also easy to get started with as a beginner because there is little boilerplate code for getting a simple app up and running. Flask backs extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, and several common frameworks related tools. Extensions are updated more regularly than the core Flask program. Flask is commonly used with MongoDB which allows it more control over databases and history.</p>
<p><strong>INSTALLING FLASK</strong></p>
<p>Before getting started, the user need to install Flask. Because systems vary, things can intermittently go wrong during these steps.</p>
<p><strong>INSTALL VIRTUALENV</strong></p>
<p>Here we will be using virtualenv to install Flask. Virtualenv is a suitable tool that creates isolated Python development environments where the user can do all his/her development work. If the user installs it system-wide, there is the risk of messing up other libraries that the user might have installed already. Instead, use virtualenv to create a sandbox, where the user can install and use the library without affecting the rest of the system. The user can keep using sandbox for ongoing development work, or can simply delete it once the user is finished using it. Either way, the system remains organized and clutter-free.</p>
<p>If you see a version number, you are good to go and you can skip to this &#8220;Install Flask&#8221; section. If the command was not found, use easy_install or pip to install virtualenv. If you are running in Linux or Mac OS X, one of the following should work:</p>
<p>$ sudo easy_install virtualenv</p>
<p>$ sudo pip install virtualenv<br />
If you are running Windows, follow the &#8220;Installation Instructions&#8221; on this page to get easy_install up and running on your system.</p>
<p><strong>INSTALL FLASK</strong></p>
<p>After installing virtualenv, the user can create a new isolated development environment, like so:</p>
<p>$ virtualenv flaskapp</p>
<p>Here, virtualenv creates a folder, flaskapp/, and sets up a clean copy of Python inside for the user to use. It also installs the handy package manager, pip.</p>
<p>Enter newly created development environment and activate it so to start working within it.</p>
<p>1<br />
2<br />
$ cd flaskapp<br />
$ . bin/activate<br />
Now, the user can safely install Flask:<br />
$ pip install Flask</p>
<p>SETTING UP THE PROJECT STRUCTURE</p>
<p>Let&#8217;s create a couple of folders and files within flaskapp/ to keep the web app organized.</p>
<p><img class="aligncenter size-medium wp-image-2715" src="http://www.pro-tekconsulting.com/blog/wp-content/uploads/2018/10/INSTALL-FLASK-262x300.png" alt="INSTALL FLASK" width="262" height="300" /></p>
<p>Within flaskapp/, create a folder, app/, to comprise all files. Inside app/, create a folder static/; this is where the user has to put the web app&#8217;s images, CSS, and JavaScript files, so create folders for each of those, as demonstrated above. As well, create another folder, templates/, to store the app&#8217;s web templates. Create an empty Python file routes.py for the application logic, such as URL routing.</p>
<p>And no project is complete without a helpful description, so create a README.md file as well.</p>
<p><strong>BUILDING A HOME PAGE</strong></p>
<p>While writing a web app with a couple of pages, it quickly becomes bothersome to write the same HTML boilerplate over and over again for each page. Also, if the user needs to add a new element to their application, such as a new CSS file, the user would have to go into every single page and should add. This is time consuming and error prone. Wouldn&#8217;t be nice if, instead of repeatedly writing the same HTML boilerplate, the user can define their page layout just once, and then use that layout to make new pages with their own content.</p>
<p><strong>APP/TEMPLATES/HOME.HTML</strong></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">1 {% extends &#8220;layout.html&#8221; %}</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">2 {% block content %}</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">3 &lt;div class=&#8221;jumbo&#8221;&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">4 &lt;h2&gt;Welcome to the Flask app&lt;h2&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">5 &lt;h3&gt;This is the home page for the Flask app&lt;h3&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">6 &lt;/div&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">7 {% endblock %}</span></span></span></span></p>
<p><strong>BUILDING AN ABOUT PAGE</strong></p>
<p>In the above section, we have seen the creation of a web template home.html. Now, let&#8217;s repeat that process again to create an about page for our web app.</p>
<p><strong>APP/TEMPLATES/ABOUT.HTML</strong></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">{% extends &#8220;layout.html&#8221; %}</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">{% block content %}</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">&lt;h2&gt;About&lt;/h2&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">&lt;p&gt;This is an About page for the Intro to Flask article. Don&#8217;t I look good? Oh stop, you&#8217;re making me blush.&lt;/p&gt;</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">{% endblock %}</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">In order to visit this page in the browser, we need to map a URL to it. Open up routes.py and add another mapping:</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">from flask import Flask, render_template</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">app = Flask(__name__)</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">@app.route(&#8216;/&#8217;)</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">def home():</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">return render_template(&#8216;home.html&#8217;)</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">@app.route(&#8216;/about&#8217;)</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">def about():</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">return render_template(&#8216;about.html&#8217;)</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">if __name__ == &#8216;__main__':</span></span></span></span></p>
<p><span style="color: #000000;"><span style="font-family: Calibri, serif;"><span style="font-size: small;"><span lang="en">app.run(debug=True)</span></span></span></span></p>
<p>The post <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog/pythons-flask/">PYTHON’S FLASK</a> appeared first on <a rel="nofollow" href="http://www.pro-tekconsulting.com/blog">Pro-Tek Blog</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pro-tekconsulting.com/blog/pythons-flask/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
