Deploy Python Flask App on Pythonanywhere.com

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone in a previous two videos who had built the back end and the front end of our video splitter application the back end was written in PI PD f2 and the front end was written in flask in this video we are going to take this application that was developed locally and deploy it on the cloud so before we do that let me just quickly demo the application that we had built so this is the PDF splitter it extracts pages from the start page and then page and saves it as a separate PDF file so let me give a start page as one and then in pages 3 and choose a sample PDF file and let me upload this so right now this upload is happening locally so let me extract and download the PDF file so I get the extracted PDF file so now let's see how we could do the same using Python anywhere so let me visit by than anyway so now let me create a new account and the beginner account so this username whatever you give here would be your domain name so let me give a flask example and then I email ID you would need to provide a email ID here and also a password so let me agree to the terms and that is pretty much it let's just hope this domain is not already taken it's taking a while for it to load okay so it's not taken so I don't want it to right now so now the first thing we need to do here is create a web app so let me head over to web here and now let me create a new web app so this will be the domain name of our application classic example dot Python anywhere com so now let me click Next and we are going to create a flask application and the version of Python that I am running is three point six so let me choose three point six and this will be the working directory wherever a code would be present and now this is going to create a folder where all our code would be present so now let me just visit this website so it is a sample flask app that button anywhere has created for us so it is just hello from flask so now what we are going to do is we are going to go to files and upload our code that we had written over here so my site is where all the application logic or the code is present let me delete this sample file generated by Python anywhere so now let me upload the files that we had written earlier so let me see where the files are located so those files are let me just copy the path here and then let me upload those files so these are the files that we had written so we need to upload them one by one I'm not sure if Python anywhere provides a version where you could upload all of them together I guess in the premium version you can do that so now we have uploaded these two files this was the flask front end and this was the back end of the media splitter that is all we need right now and then let me create a separate directory where are templates stored so templates were those HTML files that had loaded through ginger templating so that directory needs to be templates so I'll create this new directory so now once inside this templates directory I'll upload whatever the HTML files we have so I'll have to upload it one by one so successful upload and there's one more to upload download okay does not upload it one of them file upload so let me upload that so now we have written whatever the code had written locally we have uploaded it to this my site directory so this was the to Python codes and then there is this directory where the templates are present so now what we need to do is let's head over to web so now here this WSGI file needs to be edited so this is the default app that python anywhere had created we need to replace this with our application so my flask front-end the file name was app dot py so let me just replace it with app so from app it is going to import it as an application so wsj by default needs it as an application for it to work so let me save it so once I've saved I can exit out of this and let's see our site let's see if it has rendered successfully ok the still hello from flask that means that okay I need to reload it of course I didn't reload the website so once after reload let me open it again so ok something went wrong so let's see the error logs to see what are going wrong so here you can see that I've not imported the module state so it says that no module name by PDF - so let's go ahead and import this respective modules so to do that you have to head over to consoles and then go to bash because we need the PIP commands to install the rest two modules so once this loads up it's going to take a while probably to load up it's still loading for some reason let's see if there was any other error that we had got here so that was it no module named by PDF - and nothing else so it's still loading the bash interpreter this is one I can't say really a disadvantage because we are already using the free version but yeah if you had selected the pro version it would have been a bit faster so let's create a virtual environment to install our packages so it is make virtual env and then let's name a virtual environment us flask with two case and then yeah that is probably it so it's okay by default if you don't provide Python ear it's going to choose Python 2.7 which is not what we are using so let's not do that we'll create a virtual environment with Python 3 itself so now we have to head over to this virtual environment directory and delete this so let me to placate this so it by default uses Python 2.7 which is not actually a good thing so let me exit out of this and then go to files virtually in B so this is the virtually in with Python 2.7 that was created let's delete it and now we will create a new virtual and we'll okay this is not any can exit out of this year let me exit out of it and now let's create a new way and we and I hope we can specify the version of Python like this here so we are going to use python 3.6 and that will probably do it so it's going to download all the setup files the pipe and wheel so here is where location of virtual environment that it creates so once this virtual environment is created we could install all the PIP packages in here again it's going to take a while so finally the virtual environment got created it actually took a while so now that we are in the virtual environment we could install any Python package through here so let me install flask which you would need so flask could provide all the front-end app routes etc and the next thing that we would need a spy PDF to so again this might take a while so I will pause the video here so now that flask is installed let's install the next required library which is PI PDF - and for some reason it's actually taking a lot of time for it to install install and let me fix that so login pause the video here and wait for it to install it's like taking one or two minutes for it to finish installation so now that both of our libraries are installed let's quickly get out of this painfully slow bash console so here is where all the libraries were installed so flask example and virtually Envy's so within this environment we have our flask virtual environment where all our libraries were installed so now we need to provide this path for it to look for these libraries so let's do that so here we need to provide that path so the name was flask so it's going to take in just the name of the virtual environment and find that particular virtual environment which is pretty cool so now what let's test our application out to see if it's working or not so first I have to reload it so once the reload is done let me visit the application okay we can see that the web app actually got rendered successfully so let me see if it's everything is working fine so let's give a start play this one then pages three and again choose the sample PDF file and let me upload it so now with the file was uploaded then let me extract and then let me download okay so it's giving the internal server error so let's see what might have gone wrong so for that we can always have this logs here so let me go to both the error log and the server not so we can see here that okay there was no such file or directory my site and krob file so this is probably because the working directory here is set as flask example and it is trying to access a file within my site so let me change this working directory to my site itself so here let me just add my site here and that should probably do it so let me again reload this let me close all of this so then let me visit this here and let's check it out so one three and again the sample PDF file and then upload so then let me extract one two three and let's see if it downloads okay it finally worked so it downloaded the file so that is it so one thing that I would like to address in this video is that whatever you are hosting on Python anywhere for free it will only exist for three months unless you press this button so once you do this it will again extend it for three months so and in three months from today this web app would be hosted and would not require any manual intervention but after three months if you don't press this button then it would just remove that particular domain and allotted to someone else so this is pretty much it in this video thank you for watching and also please do subscribe
Info
Channel: Aditya Pai Thon
Views: 22,954
Rating: undefined out of 5
Keywords: deploy, flask, python, application, pythonanywhere, host flask, cloud hosting, free hosting, deploying application, python projects, tutorial, web hosting, deploying flask, free deploy, free servers, server python, flask server, pythonanywhere.com, free code, pdfsplitter, flask app, flask application
Id: 6p7GBfHgJq8
Channel Id: undefined
Length: 12min 6sec (726 seconds)
Published: Fri Aug 09 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.