- Create a new Python project on PythonAnywhere.
- Copy the code below into a file named "app.py": (Source)
- (Optional) Test the web app locally.
- Open a terminal and run the commands below: (Source)
Windows:
Mac:
- You should see a message saying something like "Running on http://127.0.0.1:5000/"
- Navigate to that URL and you should see the text "Hello, World!".
- Open a terminal and run the commands below: (Source)
- Add flask and its dependencies to your requirements.txt.
- Open a terminal, navigate to the folder containing your app, and run "pip freeze > requirements.txt".
- Push the changes to your Bitbucket repository and then pull them down from PythonAnywhere.
- Create a new web app in PythonAnywhere. (Source)
- Click the 'Web' tab.
- Click 'Add a new web app'.
- Choose the domain name to use.
- Select a Python Web framework: Select "Manual configuration".
- Select a Python version: Select the version that corresponds to the version you chose when creating your new project.
- Set the path to your source code.
- Note that if you have your server code in a subfolder of your Python project (like, "PROJECT_NAME/server/app.py"), it may be necessary to set the path here to the subfolder that contains the actual Python file.
- Set the path to your virtualenv.
- This is probably going to be the format: /home/YOUR_USERNAME/.virtualenvs/NAME_OF_THE_VIRTUAL_ENV
- Reload your web app.
- Set up your WSGI file.
- Open your WSGI config file.
- Scroll down to the Flask section.
- Uncomment the lines of code.
- Modify the path and module name to match your application.
- Note that if you have your server code in a subfolder of your Python project (like, "PROJECT_NAME/server/app.py"), it may be necessary to set the path here to the subfolder that contains the actual Python file.
- You should now be able to navigate to path in app.py and see the "Hello, World!" message.
- And now, further developing the website is just a very slow process of thinking to yourself, "What small/incremental thing do I know that this website needs to have that doesn't depend on something else I haven't yet coded up?", and then Googling for up to a few hours to figure out what commands you need to write to have that incremental thing added.
- Here is a very good article on how to quickly add registration to your app: https://medium.com/@perwagnernielsen/getting-started-with-flask-login-can-be-a-bit-daunting-in-this-tutorial-i-will-use-d68791e9b5b5
Related websites
- O'Reilly Media - Building Web APIs with Flask (video tutorials) - by Miguel Grinberg
- GitHub - Miguel Grinberg - oreilly-flask-apis-video - This is the repo for the code written in the video tutorials.
- MiguelGrinberg.com - Designing a RESTful API with Python and Flask
- O'Reilly Media - Flask Web Development (book) - There's a chapter on APIs.
- O'Reilly Media - Web API Development with Flask (Video tutorials) - These are not the ones by Grinberg.
- Official Flask website - Quickstart
- Only the beginning is relevant (the 'hello world' example), the rest of the page is discussing features used when building a website.
- 2014.05.12 - O'Reilly Media - Building RESTful APIs with Flask in PyCharm - blog post