Highlights:

  • I learned the general framework for how Flask works! Including the @app.route() and render_template() functions.
  • I deployed the burningvpn.com app with Google App Engine using Flask, and it works!
  • Learned that restarting the systems / computer / code solves 75%+ of my problems.

Context:

In order to build some functionality into my website (Stripe payments, account management, etc.), I need to have some server-side code to run through this logic. I’d like to use Python, since I’m most familiar with that language. 

There’s a ‘micro-framework’ called Flask that helps connects Python files with HTML / CSS / Javascript files. It’s an entirely new framework, so it’ll require some learning. Here I go with my learning.

Some tutorials that helped me:

This blog helped a lot. Spent a lot of time trying to get my form from my html page to submit to my Python file.

https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world

This guy’s blog is even more helpful. But using Flask looks a lot more complicated than I imagined! This looks like it’ll take more time to learn…

https://medium.freecodecamp.org/how-to-build-a-web-application-using-flask-and-deploy-it-to-the-cloud-3551c985e492

Here’s also another good tutorial. This one’s quite good, because it also walks through setting up this web app through GAE.

Some issues I encountered:

  • Issue: We have to re-arrange our .html and other files.
    • Context: Currently, my workflow is I create a simple landing page on carrd.co. Once the layout is created, I’ll download the html files and other assets (pictures, .css files, etc.). After downloading the website files, I’ll upload them to our Google Apps Engine, so we can host them on burningvpn.com with SSL certificates.
    • This method does not allow for interoperability with Python code. I intend to use the Stripe API with Python, since that’s the language I’m most familiar with. 
    • When using Flask, I have to move our .html files to a `templates` folder. This messes up the endpoints within the index.html file that I download from Carrd.
  • Solution: Manually move the files and update the endpoints. Flask requires you put all of your .html files into a ‘template’ folder. All of your other assets (.css files, images, etc.) go into a `static` folder.
  • Issue: I will have to make edits to our website on carrd.co in the future, since it’s easiest to arrange the layout there. So next time I make edits and download those website files to upload to my GAE, I have to make the same updates to the .html code
  • Solution (for now): just do it.
  • Issue: By moving all the files and updating the endpoints, I get some errors when I try to run the app locally on my computer. Perhaps I have to update the .css and .js files too? 
  • Solution: I didn’t update the endpoints correctly. I forgot to use ../ to go up one folder level to get to the right place.
  • Issue: I have some issue running the Python code. I am wondering if it’s because Google SDK only works only Python 2.7? Currently, my environment is Python 3.5. Some of my Python code doesn’t work on 2.7. Will have to learn that older syntax.
  • Solution: I moved my virtual environment to Python 2.7. The python print statement has slightly different syntax between Python 3.x and Python 2.x. I just commented it out.

Things I’d like to find out (eventually):

  • How do I find out where these html assets are being pulled from? For example, where is the bg.jpg being called? I edited one endpoint in my `main.css` file, but it doesn’t seem to be working. I can’t find any other file that references this file. How do I found out where this file is being called?
  • How do I output print statements when I’m deploying webapps using Flask and Python? How can I debug these Python issues?
Ching Jui Uncategorized , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *