{"id":4003,"date":"2019-10-20T09:03:25","date_gmt":"2019-10-20T07:03:25","guid":{"rendered":"https:\/\/pythonprogramming.altervista.org\/?p=4003"},"modified":"2019-10-27T14:02:10","modified_gmt":"2019-10-27T13:02:10","slug":"python-3-with-flask-on-glitch-com","status":"publish","type":"post","link":"https:\/\/pythonprogramming.altervista.org\/python-3-with-flask-on-glitch-com\/","title":{"rendered":"Python 3 with Flask on Glitch.com!"},"content":{"rendered":"<p>Finally we can use <strong>Python<\/strong> <strong>3<\/strong> on <strong>Glitch<\/strong>.com with <strong>Flask<\/strong> to create app or sites or blogs or whatever you need to be on the web with the beauty of Python, the most elegant language ever.<\/p>\n<p>In the following video you will see me exploring the remixed code to use flask with <strong>Python 3 on glitch.com<\/strong>. I talked about glitch.me and flask in many posts, but I always used python 2 for that. Now I found this code and tried it on my sites and I saw all the benefits of this upgrade.<\/p>\n<p>Why?<\/p>\n<ul>\n<li>First: I use Python 3, so I am more at ease with it;<\/li>\n<li>second: Python 2 will be non longer supported<\/li>\n<li>third: it is faster, the changes on the site (even in the html files) are now immediate, while it took some minutes with python 2 (you could not predict when the changes would be applied and if there was something that was not going well, so now it is a pleasure to see immediately the effect of your modifications)<\/li>\n<\/ul>\n<h2>What you need to do it<\/h2>\n<p>You need these files:<\/p>\n<ul>\n<li>InstallReqsAndStart.sh<\/li>\n<li>package.json<\/li>\n<li>watch.json<\/li>\n<li>server.py<\/li>\n<\/ul>\n<h2>InstallReqsAndStart.sh<\/h2>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\r\n\r\nMD5=$(md5sum .requirements.txt | cut -f1 -d' ')\r\nif ! [ -d \".data\/$MD5-site-packages\" ]; then\r\n    rm -rf .data\/*-site-packages\r\n    pip3 install -U -r .requirements.txt -t \".data\/$MD5-site-packages\" \r\nfi\r\nexec env PYTHONPATH=\"$PWD\/.data\/$MD5-site-packages\" python3 server.py<\/pre>\n<h2>package.json<\/h2>\n<pre class=\"lang:default decode:true \">{\r\n  \"\/\/1\": \"describes your app and its dependencies\",\r\n  \"\/\/2\": \"https:\/\/docs.npmjs.com\/files\/package.json\",\r\n  \"\/\/3\": \"updating this file will download and update your packages\",\r\n  \"name\": \"my-glitch-app\",\r\n  \"version\": \"0.0.1\",\r\n  \"description\": \"What am I about?\",\r\n  \"scripts\": {\r\n    \"start\": \"bash installReqsAndStart.sh\"\r\n  },\r\n  \"dependencies\": {},\r\n  \"engines\": {\r\n    \"node\": \"9.x\"\r\n  },\r\n  \"repository\": {\r\n    \"url\": \"https:\/\/glitch.com\/edit\/#!\/my-glitch-app\"\r\n  },\r\n  \"license\": \"MIT\",\r\n  \"keywords\": [\r\n    \"node\",\r\n    \"glitch\",\r\n    \"express\"\r\n  ]\r\n}<\/pre>\n<h2>requirements.txt<\/h2>\n<pre class=\"lang:default decode:true \">Flask<\/pre>\n<h2>server.py<\/h2>\n<p>This will create just a line with two words (Hello World) in the page. To see how to create a complex site, go in the links at the end of the post.<\/p>\n<pre class=\"lang:default decode:true\">from flask import Flask\r\napp = Flask(__name__)\r\n\r\n@app.route(\"\/\")\r\ndef hello():\r\n  return \"Hello World!\"\r\n\r\napp.run()<\/pre>\n<p>&nbsp;<\/p>\n<h2>The video with the live discovery of Python 3 on Glitch.com<\/h2>\n<p><iframe loading=\"lazy\" title=\"Python 3 - Site with Flask on Glitch.com\" width=\"747\" height=\"420\" src=\"https:\/\/www.youtube.com\/embed\/ZXcSGX3MMNI?feature=oembed&amp;enablejsapi=1\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h2>Examples of sites with flask and python3<\/h2>\n<ul>\n<li><a href=\"https:\/\/python3-8.glitch.me\/\">First site with tkinter<\/a> (it is a wip, you&#8217;ll find things for the other site about PIL)<\/li>\n<li><a href=\"https:\/\/pil.glitch.me\/\">Second site<\/a> (it is the one fot PIL&#8230; converted from python 2 to python 3 as you see in the video<\/li>\n<li>The <a href=\"https:\/\/glitch.com\/edit\/#!\/pil\">code of the second site<\/a><\/li>\n<\/ul>\n<h2>How to import the code you see in pil.glitch.me<\/h2>\n<p>Go in\u00a0<strong>tool<\/strong> in the left bottom of the screen of the glitch page and then, from the menu, click on import from glitch (2 times). On the pop up window insert formazione\/flask and you will get the code that you will personalize.<\/p>\n<script>\r\n\tif (typeof title != \"undefined\")\r\n\t{let title = \"Glitch.com (with flask)\";\r\n\tlet links = [];}\r\n\telse\r\n\t{title = \"Glitch.com (with Flask)\";}\r\n\r\n\tlinks = [\r\n[\"https:\/\/pythonprogramming.altervista.org\/how-to-authorize-users-to-access-to-personal-pages-with-glitch-com\/\",\"Access with auth on glitch.me\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/video-python-3-on-glitch-com\/\",\"Python 3 on Glitch (Live code)\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/flask-and-python-3-on-glitch-in-a-couple-of-lines\/\",\"Python 3 on Glitch with Flask (2)\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-on-glitch-com-without-flask\/\",\"Python on Glitch.com without flask\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-3-with-flask-on-glitch-com\/\",\"Python 3 on Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/python-flask-on-glitch-edited-with-visual-studio-code\/\",\"Visual studio code and Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/how-to-import-a-blog-on-glitch-com-from-github\/\",\"Import site from Github in Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/publish-app-or-blog-with-glitch-com-and-python-in-no-time\/\",\"Publish a Flask Blog in Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/put-our-flask-blog-on-glitch-com-for-free\/\",\"Free Flask blog wiht Python on GLitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/a-brief-guide-to-pil-python-image-library\/\",\"My Flask site on PIL on Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/how-to-render-html-into-flask-variables-passed-to-the-pages\/\",\"Render Html in Flask on Glitch.com\"],\r\n[\"https:\/\/pythonprogramming.altervista.org\/what-if-you-got-dns_probe_finished_nxdomain-with-glitch-me-sites\/\",\"Cannot see glithc.me site (dns)\"]\r\n\t\t];\t\t \r\n<\/script>\r\n<script>\r\n\t\r\nif (typeof next2 != \"undefined\"){let next2 = 0;}\r\n\t\r\nnext2 = 0;\r\n\thtml = \"\";\/\/<b style='color:coral;font-size:1.2em'>Other posts about \" + title + \"<\/b><br>\";\r\nfor (address of links) \r\n{\r\n\r\n\tif (next2 == 1){\r\n\t\thtml += \"<div style='background:coral'>\";\r\n\t\thtml += \"Next link => <a href='\" + address[0] + \"'>\" + address[1] + \"<\/a>\";\r\n\t\thtml += \"<\/div><br>\";\r\n\t\tnext2 = 0;\r\n\t}\r\n\tif (address[0] == document.URL) {\r\n\t\tnext2 = 1;\r\n\t}\r\n}\r\n\r\nif (typeof next != \"undefined\") {let next = 0;}\r\nif (typeof addressStart != \"undefined\") {let addressStart = \"\";}\r\nnext = 0;\r\naddressStart = \"<a href='\";\r\nfor (address of links) {\r\n\tif (next == 1){\r\n\t\thtml += \">>>\" + addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t\tnext = 0;\r\n\t}\r\n\telse if (addressStart + address[0] != document.URL)\r\n\t{\r\n\t\thtml += addressStart + address[0] + \"'>\" + address[1] + \"<\/a><br>\";\r\n\t}\r\n\telse\r\n\t{\r\n\t\tnext = 1;\r\n\t\tnext_address = address[0]\r\n\t\tnext_title = address[1]\r\n\t\thtml += \"<span style='color:gray'>\" + address[1] + \"<\/span><br>\";\r\n\t}\r\n\r\n}\r\n\r\n\thtml += `<span style=\"font-size:8px\">Powered by <a href=\"https:\/\/pythonprogramming.altervista.org\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2673\" src=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png\" alt=\"\" width=\"70\" height=\"25\" srcset=\"https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2.png 156w, https:\/\/pythonprogramming.altervista.org\/wp-content\/uploads\/2019\/06\/altervista2-150x56.png 150w\" sizes=\"auto, (max-width: 70px) 100vw, 70px\" \/>pythonprogramming.altervista.org<\/a><\/span>`\r\n\thtml = \"<div style='background:yellow'>\" + html + \"<\/div>\";\r\n\tdocument.write(html)\r\n<\/script>\n","protected":false},"excerpt":{"rendered":"Python 3 can be used on Glitch.com \/ Glitch.me&#8230; with flask, let&#8217;s see how\n<a class=\"moretag\" href=\"https:\/\/pythonprogramming.altervista.org\/python-3-with-flask-on-glitch-com\/\"> [...]<\/a>","protected":false},"author":1,"featured_media":4004,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[1,420,431],"tags":[346,433,538,4,603],"class_list":["post-4003","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-examples","category-flask","category-glitch-com","tag-flask","tag-glitch-com","tag-glitch-me","tag-python","tag-python-3"],"avopt_banners_inside_post":true,"avopt_banners_on_page":true,"av_copy_from":"","av_sharing_message":"","av_sharing_allowed":false,"av_sharing_on":{"fb":[],"tw":[]},"av_allow_affiliate_banner":false,"av_allow_affiliate_multi_banner":false,"av_show_affiliation_buy_button":false,"av_post_rating":true,"av_have_post_rating_value":false,"av_is_artificial_intelligence_content":false,"_links":{"self":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/comments?post=4003"}],"version-history":[{"count":7,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4003\/revisions"}],"predecessor-version":[{"id":4059,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/posts\/4003\/revisions\/4059"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media\/4004"}],"wp:attachment":[{"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/media?parent=4003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/categories?post=4003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pythonprogramming.altervista.org\/wp-json\/wp\/v2\/tags?post=4003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}