DEV Community

kjvmartinez
kjvmartinez

Posted on

2

Deploy Django project in Pythonanywhere

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.

Image description

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.

Image description

  • 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())

Enter fullscreen mode Exit fullscreen mode

c. Check the virtual environment settings. You can just type the virtual environment name (myvenv).

Image description

d. Setup the directory of your static files.

Image description

e. Reload the project and check if the site is running.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay