If you are learning Django and you want to host your Django app online, you need a perfect web hosting solution. There are lot of online services that offer Python hosting solutions, but when hosting your app for the first time, you need an easy-to-use solution. PythonAnywhere is one of the great option for newbies.
PythonAnywhere offers both free and paid hosting solutions for Python based apps . The free version only allows you to host your app on a PythonAnywhere based subdomain. If you purchase a paid version (starting at $5 per month), you can set up one main domain and use a MySQL database. I advise choosing MySQL or PostgreSQL as the database for your Python app. Using SQLite on PythonAnywhere can affect your site's speed.
If you switch to a custom plan, you can use both MySQL and PostgreSQL databases. The custom plan also allows you to add several main domains, adjust file storage size, and increase PostgreSQL database size. You can set up the payment settings as a monthly recurring payment from your credit card. If you host two domains with a PostgreSQL database, it will cost approximately $14.
Once you know how to host Django apps online, you can easily switch to another hosting solution. Therefore, I highly recommend PythonAnywhere as your first Python hosting provider, as it helps you save a lot of time you would otherwise spend on hosting setup.
So, how do you host your Django app on PythonAnywhere?
1. First, create a PythonAnywhere account. Choose 'Beginner account' if you plan to add a test Django app in a PythonAnywhere subdomain. Choose 'Hacker account' if you want to host your Django app on a custom domain name.
2. Then create a public or private repository on GitHub and add your Django app code to that repository.
3. Create a virtual environment in PythonAnywhere using the Bash console, and clone your GitHub repository into PythonAnywhere. Activate the virtual environment and install the required Python packages using the requirements.txt file.
Step 1: Open bash console in Pythonanywhere and type the following command in bash
git clone git@github.com:gitusername/appname.git
Then create a virtual environment using the following command
mkvirtualenv venv
Use the following command to see the project working directory
pwd
To see the all files listed in the working directory, use the following command
ls
it will list the files and directories like this
README.txt appname
To navigate the folder, use the follwoing command
cd appname
Now install the Django and required packages either from requirements.txt file or using the pip command
pip install -r requirements.txt
Watch this video 'Deploy a Django Web App on PythonAnywhere." to see more info about How to Deploy a Django App on PythonAnywhere.
© 2024 Webapptiv. All rights reserved.