import re with open('config/settings.py', 'r') as f: content = f.read() middleware = """MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', """ content = re.sub(r"MIDDLEWARE = \[\n\s+'django\.middleware\.security\.SecurityMiddleware',\n", middleware, content) static_root = """STATIC_URL = 'static/' STATIC_ROOT = BASE_DIR / 'staticfiles' STATICFILES_DIRS = [BASE_DIR / 'static'] """ content = re.sub(r"STATIC_URL = 'static/'\n", static_root, content) with open('config/settings.py', 'w') as f: f.write(content) with open('requirements.txt', 'a') as f: f.write('\nwhitenoise==6.7.0\n')