May 25, 2023, 8:01 p.m.

How to deploy a django website on pythonanywhere | django Web app deploying issues

It's a little bit annoying to find the best hosting service for your website when the development is completed. There are several hosting services which provides different plans to host a website. But it is very important to choose the right one because the speed does matter.
Today i am going to teach you that how you can deploy your website on Pythonanywhere
i will keep the process simple and step by step to make better understanding.
PythonAnywhere runs on super-powerful servers hosted by Amazon EC2 , and you can take full advantage of that. This is the main reason for selecting Pythonanywhere for web hosting. You can run or test your django web app on pythonanywhere for free (3 months free trial) .
Although if you want to use some other hosting services then you should visit any of the link from the following list.

7 best Web hosting services for django 1. PythonAnywhere
2. Heroku
3. A2 Hosting
4. AWS
5. HostUpon
6. TMD Hosting
7. DigitalOcean

Step 1 If you face any issue between the whole process then you can scroll down and read the "TIPS".
Make zipfile of your project and upload it on pythonanywhere's "Files" tab.
Now we have to unzip the zipped file, run the console by clicking "Open bash console here". (please do not close the console untill the process is completed).
Run the following command to unzip the uploaded file :
unzip ProjectFileName
Here are some basic linux commands which we will use in this process -
You can use pwd command to find working directory
ls for list directory
cd projectname/ to enter/open a directory (here projectname)

Now create & set a virtual environment by using the following commands :
unzip ProjectFileName
mkvirtualenv --python=/usr/bin/python3.7 myenv
pip install django
cd ProjectFileName
python collectstatic

Type the above commands carefully and i assure you will not get any error if everything is done carefully. You will find (myenv) XX ~ $ symbol if a virtual environment (i.e of name myenv) is created, as shown in the image below.

image not found
Step 2 Now go to WEB tab
click Add a new web app
choose Mannual configuration

Now, set "Virtualenv:" to "myenv" (just write the name of virtual environment, it will find the path automatically)

image not found
Step 3 Now go to Code: area and
click on WSGI configuration file :
note that we have to write "path" and "settings" path values only.
1) Erase everything except django code.
2) Remove lines with '#' , not lines with '##'
see the example code below :

image not found
Step 4 Now reload the server. Note that "" is your domain name for free plan on pythonanywhere. You may get DissallowedHost at / error if you run the website.
Now go to your project directory and set the following code in file :
save the file by pressing "ctrl+s" or by pressing the save button.

Step 5 Now go to Web tab and scroll down to Static files:
Insert the static and media path/url in this field and shown in figure below.
Note :
The url or path which i write in "" file and in "Static files:" are case sensitive, please do not copy and paste the paths from the provided example code directly.

image not found
Step 6 Now run the collectstatic command again i.e
python collectstatic
We are done now , just reload the server and run the web application. If you followed all the steps carefully and gently then everything is all set now.

But, i am listing some tips for debugging common issues that may be faced by users.
First of all remember that you need all the modules which your app is using. If the pythonanywhere shows an error log page (as shown in image below) , it means that either their is some mistake in your code or there is/are modules which is/are not installed in virtual environment. To install any module you have to run the console in your virtual environment for this, go to Web tab ,scroll down a little bit and click on Start a console in this virtualenv in "Virtualenv:" field.
Now use pip install ModuleName command directly to install any module in your virtual environment.
It is required to install "pillow" if there are images on your website. So install pillow in the virtual environment by starting a console in your virtual environment.

image not found

Some recent posts

How to deploy a django website on pythonanywhere | django Web app deploying...

Complete process of changing database from SQLite to MySQL - How to migrat...

" How to download a file in django | Making a large file downloadable from ...

How to use proxy in python requests | http & https proxies - Scraping...

Top Django Querysets, How to filter records | Fetching data from database e...

How to change base url or domain in sitemap - Django ...

How to Make a Website - Everything you should know about web development...

What is Javascript - Features and usages ...

Top 5 Interview Questions : Tips for HR round ...

How to get job in IT : Perfect resume guide for IT job ...

View all...