Skip to content

Instantly share code, notes, and snippets.

@rguliev
Last active July 16, 2024 14:41
Show Gist options
  • Save rguliev/d0d4e5688c8a27b5c7e8470752288395 to your computer and use it in GitHub Desktop.
Save rguliev/d0d4e5688c8a27b5c7e8470752288395 to your computer and use it in GitHub Desktop.
Passenger WSGI settings with virtualenv and StaticFilesHandler
# -*- coding: utf-8 -*-
import os, sys
sys.path.insert(0, '<abs path to the project>')
sys.path.insert(1, '<abs path to the venv>/lib/python3.6/site-packages')
# Use python from virtual env.
INTERP = os.path.expanduser("<abs path to the venv>/bin/python")
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
os.environ['DJANGO_SETTINGS_MODULE'] = 'ibcp_scripts.src.settings'
from django.core.wsgi import get_wsgi_application
# Use SatticFilesHandler in DEBUG mode
from django.conf import settings
from django.contrib.staticfiles.handlers import StaticFilesHandler
if settings.DEBUG:
application = StaticFilesHandler(get_wsgi_application())
else:
application = get_wsgi_application()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment