Deploy Django project in Pythonanywhere
kjvmartinez
Posted on October 22, 2022
If you have a Django project and want to deploy this in pythonanywhere this article is for you.
The project should be available in your GitHub repository.
First, create an account in pythonanywhere for your project in this link https://www.pythonanywhere.com/registration/register/beginner/. Verify and log in to your account.
a. In the Dashboard > Console click the $ Bash
button.
To make sure you’re in /home/username
$ pwd
Clone your project from GitHub repository
$ git clone [paste-your-url-here]
Create virtual environment
$ virtualenv myvenv –python = python3.7
Activate the virtual environment
$ source myvenv/bin/activate
Go to the directory where you can find the requirements.txt Install the requirements
$ pip install -r requirements.txt
Go to the directory where you can find the manage.py and migrate your database.
$ python manage.py makemigrations
$ python manage.py migrate
b. Go to the Web page and configure the WSGI file by clicking on the link WSGI configuration file. Paste the code below.
- path should be equal to the path where your manage.py can be found
import os
import sys
path = '/home/csopac/csopac/projectsite/'
if path not in sys.path:
sys.path.insert(0, path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'projectsite.settings'
from django.core.wsgi import get_wsgi_application
from django.contrib.staticfiles.handlers import StaticFilesHandler
application = StaticFilesHandler(get_wsgi_application())
c. Check the virtual environment settings. You can just type the virtual environment name (myvenv).
d. Setup the directory of your static files.
e. Reload the project and check if the site is running.
Posted on October 22, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.