Install an existing Django Webapp on Pythonanywhere.com

Post #228 written by Khodok in Code

Content

Documentation

First steps

  1. On Pythonanywhere
    • From a fresh start with no apps, go into account -> token and create one.
    • Open a console and execute pip install --user pythonanywhere then pa_autoconfigure_django.py --python=3.8 https://github.com/<GithubUser>/<repo>.git
  2. In Web Tab
    • Create a new web app with a custom installation (not Django)
    • Copy the CNAME and paste it where you want it on your registrar
    • Set the source code directory
    • Put this in the wsgi file
Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# This file contains the WSGI configuration required to serve up your
# Django app
import os
import sys

# Add your project directory to the sys.path
settings_path = '/home/<User>/<app-url.eu.pythonanywhere.com' # Don't forget to update this !!!
sys.path.insert(0, settings_path)

# Set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = '<project_app>.settings' # Don't forget to update this !!!

from dotenv import load_dotenv
project_folder = os.path.expanduser('~/<app-url.eu.pythonanywhere.com') # Don't forget to update this !!!
load_dotenv(os.path.join(project_folder, '.env'))

# Set the 'application' variable to the Django wsgi app
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
  1. venv

    • Install dependencies and make sure the correct venv is used
    • In a new console type pip install -r requirements.txt
    • In the web tab click on the virtual env box and enter the whole path to the virtualenv
    • If there is npm stuff to install, do it
    • Execute all the common django commands (makemigrations, migrate, etc)
  2. Static and media files

    • In Web tab set the wanted path to both
  3. I probably forgot something lmao

Comments

Please Log in to leave a comment.

No comments yet.