Omar Khalil
@omar_linux
About
Linux enthusiast and open source contributor
Q&A Statistics
All Answers
Re: How to format strings in Python
name = "John" age = 30 # f-strings (Python 3.6+, recommended) message = f"Hello, {name}. You are {age}." # format() …
Re: How to send emails in Django
Configure email settings # settings.py EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = 'your-email@gmail.com' …
Re: How to work with environment variables in Python
Reading environment variables import os # Get with default value database_url = os.getenv('DATABASE_URL', 'sqlite:///db.sqlite3') # Get (raises KeyError if not …
Re: How to change hostname on Linux
Change hostname # View current hostname hostname hostnamectl # Change hostname (systemd) sudo hostnamectl set-hostname new-hostname # Edit hosts file …
Re: How to add swap space on Linux
Create swap file # Create 4GB swap file sudo fallocate -l 4G /swapfile # Or using dd sudo dd if=/dev/zero …
Re: PostgreSQL connection refused in Django - solutions
This is usually a configuration issue. Here's how to fix it: Check PostgreSQL is listening # Check PostgreSQL status sudo …