TLDR; In this tutorial, I describe every step on how to deploy and publish your app on pythonanywhere. I am personally really convinced by the hosting service. If you are creating an account via my affiliate links you support my work and further tutorials in this direction. Show Overview
Create a beginner accountClick this link to start: pythonanywhere.com*. You can start with a beginner account. It is totally free for three months and comes with HTTPS encryption and MySQL Database. Screenshot from pythonanywhere.com by authorScreenshot from pythonanywhere.com by authorYou will be redirected and you can start the tour. Screenshot from pythonanywhere.com by authorAlso, do not forget to confirm your email address. Initialize a web app(1) We can start now to add a new web app. It is pretty easy. Go to the Web tab. And add a new web app. Screenshot from pythonanywhere.com by authorIt is opening a window, if you have a paid account, you could enter a customized URL. But, it is not relevant for now, you can modify it later. Screenshot from pythonanywhere.com by authorSelect a python framework, just choose “manual configuration” and select a python version. I chose 3.9. Screenshot from pythonanywhere.com by authorScreenshot from pythonanywhere.com by authorEt voilà done! Screenshot from pythonanywhere.com by authorAvailable PlansLater, if you feel comfortable, you can do the “Hacker“ Plan for 5 $ USD. Is it enough for running a basic website like a portfolio? I had it for almost one year. Then I changed to the “Web dev” plan because I implemented another webpage. You can also customize any plan by parameters like CPU, the number of apps, or disk space. Compared to other services like DigitalOcean it is way cheaper because you have so much extra included. Screenshot from pythonanywhere.com by authorScreenshot from pythonanywhere.com by authorSetup BackendGo to the Console tab and open a new bash console. Screenshot from pythonanywhere.com by authorClone my repo from GitHub. Screenshot from pythonanywhere.com by authorCreate a virtual environment for your web app. Here is a good help on how to do it: https://help.pythonanywhere.com/pages/Virtualenvs/. mkvirtualenv webpage_env --python=/usr/bin/python3.9 Screenshot from pythonanywhere.com by authorNow, we have to install the required libraries: pip install -r requirements.txt Web ConfigurationNext, head to the tab Web on pythonanywhere and set up the last configurations: Under Code, set up your “source code” directory, where your app folder is: Screenshot from pythonanywhere.com by authorYou get the information when initializing the virtual environment in your bash console: Screenshot from pythonanywhere.com by authorThen, configure the wsgi.py as follows: Screenshot from pythonanywhere.com by authorBelow ++++++++++ FLASK +++++++++++ uncomment the lines for import sys and change your working directory as above. Also, edit your import statement. In this case, our run.py file is the main file. from run import app as application Screenshot from pythonanywhere.com by authorComment any other lines and save your changes. Also, put the directory for your virtual environment under Virtualenv. Screenshot from pythonanywhere.com by authorThen reload and go to the URL: http://testaccountab2022.pythonanywhere.com/ Screenshot from pythonanywhere.com by authorEnable HTTPS also: Screenshot from pythonanywhere.com by authorIt should display: Screenshot from pythonanywhere.com by authorCongratulations you are done! Just modify this example to your needs and run it on pythonanywhere.com* for it. Thanks for reading my article. I hope you liked it. Please feel free to like, share, and comment on it. Follow me on more content about cryptos, stocks, data analysis, and web development. I am hosting my apps on pythonanywhere.com*.
Disclaimer*affliate links More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter, LinkedIn, YouTube, and Discord. How do I access MySQL database in PythonAnywhere?To start using MySQL, you'll need to go to the MySQL tab on your dashboard, and set up a password. You'll also find the connection settings (host name, username) on that tab, as well as the ability to create new databases. In this: The USERNAME is the username you use to log in to PythonAnywhere.
How do I use PythonAnywhere with a Flask?Make sure you have signed up for a free PythonAnywhere account, and you're logged in. Go to the Web menu item and then press the Add new web app button. Click Next, then click on Flask and click on the latest version of Python that you see there. Then click Next again to accept the project path.
Can I use MySQL with Flask?Here are the 4 steps to get started with Flask MySQL Database Connection: Flask MySQL Step 1: Connecting a Flask Application to a MySQL Database. Flask MySQL Step 2: Configuring the MySQL Connection Cursor. Flask MySQL Step 3: Programming a Flask Application.
Does PythonAnywhere have database?Databases available
There are three databases built in to PythonAnywhere: MySQL, which is available for every user. SQLite, which is also available for everyone, but runs a bit slowly on our system -- we recommend you only use it for testing or for scripts that don't do a lot of processing.
|