| What I love about Django is that you can create a Django project with just one file. You can turn a fresh Debian machine into a running Django web app by just doing: apt install -y python3-django apache2 libapache2-mod-wsgi-py3
And then creating the one file Django needs:/var/www/mysite/mysite/wsgi.py: import os
import django
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.wsgi')
application = get_wsgi_application()
ROOT_URLCONF = 'mysite.wsgi'
SECRET_KEY = 'hello'
def index(request):
return django.http.HttpResponse('This is the homepage')
def cats(request):
return django.http.HttpResponse('This is the cats page')
urlpatterns = [
django.urls.path('', index),
django.urls.path('cats', cats),
]
And then telling Apache where to look for it:/etc/apache2/sites-enabled/000-default.conf: ServerName 127.0.0.1
WSGIPythonPath /var/www/mysite
<VirtualHost *:80>
WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py
<Directory /var/www/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
And voilá, you have a running Django application, which you can expand upon to any size and complexity.If you want to try it in a docker container, you can run docker run -it --rm -p80:80 debian:12
perform the steps above and then access the Django application at 127.0.0.1 |