How to deploy a django website on pythonanywhere | django Web app deploying issuesIt'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
3. A2 Hosting
6. TMD Hosting
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 :
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 :
mkvirtualenv --python=/usr/bin/python3.7 myenv
pip install django
python manage.py 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.
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)
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 :
Now go to your project directory and set the following code in settings.py file :
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.
The url or path which i write in "settings.py" file and in "Static files:" are case sensitive, please do not copy and paste the paths from the provided example code directly.
python manage.py 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.
Some recent posts
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...
Top 5 Interview Questions : Tips for HR round ...
How to get job in IT : Perfect resume guide for IT job ...
Programming vs coding | difference between programming and coding ...
Popular PostsHow to compress image before saving to DB
Migrating from SQLite to MySQL in Django
Choosing correct M.2 SSD
How to deploy a web app on pythonanywhere
5 Steps to create sitemap in Django
How to send mails automatically in Django
Handling arguments in django urls
Media and Static configuration in Django
Language Translation & detection using python
React Js vs Angular Js
5 Tips to improve Programming Logics