Python AnyWhere Deployment
Method 1: By Creating & Uploading a Django Project
- Create your account on Python Anywhere (opens in a new tab).
- Make sure you have a Django project on GitHub.
⚠️
Note: You can deploy only one web app on the free plan.
Create a new web app
- Go to the dashboard and click on the
Web
tab. - Click on the
Add a new web app
button. - Select the
Manual configuration
option. - Choose the
Python
option. - Set the
Python version
to the version you are using. - Set the
Web app name
to the name of your project. - Click on the
Next
button.
Your web app will be created.
Enable HTTPS
- Enable the Force HTTPS option.
- You can view you web app at
https://yourusername.pythonanywhere.com
.
Uploading your project
- Go to the
Files
tab and click on theUpload a file
button. - Make sure your project is in a zip file.
- Upload the zip file.
Unzipping your project
- Go to the
Consoles
tab and open a new console. - Run the following command to unzip your project:
Terminal
# List the files in the current directory
ls -l
# Unzip the project
unzip your_project.zip
Setting up the web app
- Go to the
Web
tab and click on theReload
button. - Set the
Source code
to the path of your project. - Set the
static files
to the path of your project'sstatic
folder. - Set the
media files
to the path of your project'smedia
folder. - Set the
WSGI configuration file
to the path of your project'swsgi.py
file. Open in new tab.
wsgi.py
import os
import sys
# add your project directory to the sys.path
project_home = '/home/mohdirfan/your_project'
if project_home not in sys.path:
sys.path.insert(0, project_home)
# set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = 'your_project.settings'
# serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
- Save the changes and reload the web app.
- Go to
Files
tab and update thesettings.py
file. - Change
ALLOWED_HOSTS
insettings.py
to['yourusername.pythonanywhere.com']
or['*']
.
Now you can view your web app at https://yourusername.pythonanywhere.com
.
Method 2: Using Github
3. Set up the web app
- Set the
Web app configuration
to the path of your project. - Set the
WSGI configuration file
to the path of your project'swsgi.py
file.
3. Install requirements
- Go to the
Consoles
tab and open a new console. - Run the following command to install the requirements:
Terminal
pip install -r requirements.txt