Articles on Trending Technologies

Technical articles with clear explanations and examples

Sending an HTML e-mail using Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 800 Views

When you send a text message using Python, all the content is treated as simple text. Even if you include HTML tags in a text message, it is displayed as simple text and HTML tags will not be formatted according to HTML syntax. However, Python provides the option to send an HTML message as actual HTML content. While sending an email message, you can specify a MIME version, content type and character set to send an HTML email that renders properly in email clients. Basic HTML Email Structure To send HTML email, you need to set the ...

Read More

Disconnecting Database in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 6K+ Views

When working with databases in Python, it's essential to properly close connections to free up resources and ensure data integrity. The close() method is used to disconnect from the database. Basic Syntax To disconnect a database connection, use the close() method − connection.close() Complete Example with SQLite Here's a complete example showing how to connect to a database, perform operations, and properly close the connection − import sqlite3 # Create connection connection = sqlite3.connect(':memory:') # In-memory database for demo cursor = connection.cursor() # Create a table and insert ...

Read More

Commit & RollBack Operation in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 725 Views

Database transactions in Python require careful management of commit and rollback operations. These operations ensure data integrity by allowing you to either save changes permanently or undo them completely. Understanding Transactions A transaction is a sequence of database operations that must be completed as a single unit. If any operation fails, the entire transaction can be rolled back to maintain data consistency. COMMIT Operation The commit() method finalizes all changes made during the current transaction. Once committed, changes become permanent and cannot be reverted. Example import sqlite3 # Connect to database conn ...

Read More

Database INSERT Operation in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 582 Views

The INSERT operation is used to add new records to a database table in Python. This operation requires establishing a database connection, preparing SQL statements, and handling transactions properly. Basic INSERT Statement The following example executes an SQL INSERT statement to create a record in the EMPLOYEE table ? #!/usr/bin/python import MySQLdb # Open database connection db = MySQLdb.connect("localhost", "testuser", "test123", "TESTDB") # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to INSERT a record into the database sql = """INSERT INTO EMPLOYEE(FIRST_NAME, ...

Read More

How To Raise a "File Download" Dialog Box in Python?

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 601 Views

Sometimes, you want to provide a download link that triggers a "File Download" dialog box instead of displaying the file content directly in the browser. This can be achieved by setting specific HTTP headers that instruct the browser to treat the response as a downloadable file. Basic File Download Example Here's how to create a simple file download response using Python CGI ? #!/usr/bin/python3 import sys # Set HTTP headers for file download print("Content-Type: application/octet-stream; name="example.txt"") print("Content-Disposition: attachment; filename="example.txt"") print() # Empty line to separate headers from content # Read and output file ...

Read More

File Upload Example in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 10K+ Views

File upload in Python can be implemented using the CGI (Common Gateway Interface) environment. This involves creating an HTML form for file selection and a Python script to handle the server−side file processing. The file upload process consists of two main components: an HTML form that allows users to select files, and a Python CGI script that processes and saves the uploaded files to the server. Creating HTML Form for File Upload The HTML form uses to create a file selection field and for the upload button. The form must include enctype="multipart/form-data" to handle file ...

Read More

Passing Checkbox Data to CGI Program in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 687 Views

Checkboxes are used when more than one option is required to be selected. In web forms, checkbox data is sent to CGI programs where it can be processed using Python's cgi module. HTML Form with Checkboxes Here is example HTML code for a form with two checkboxes − Maths Physics Form Output The result of this code is the following form − Maths Physics Select ...

Read More

Passing Information Using POST Method in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 711 Views

The POST method is a more secure and reliable way to pass information to a CGI program compared to GET. Instead of appending data to the URL, POST sends information as a separate message through standard input, making it ideal for sensitive data and large forms. How POST Method Works Unlike GET method which appends data to the URL after a ?, POST method: Sends data as a separate message body Doesn't expose sensitive information in the URL Can handle larger amounts of data Provides better security for form submissions Example: CGI Script for ...

Read More

Passing Information using GET method in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

The GET method sends encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows − http://www.test.com/cgi-bin/hello.py?key1=value1&key2=value2 The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser's Location box. Never use GET method if you have password or other sensitive information to pass to the server. The GET method has size limitation: only 1024 characters can be sent in a request string. The GET method sends information using ...

Read More

CGI Environment Variables in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

All CGI programs have access to environment variables that contain important information about the request, server, and client. These variables play an important role while writing any CGI program. Common CGI Environment Variables Variable Name Description CONTENT_TYPE The data type of the content. Used when the client is sending attached content to the server (e.g., file upload). CONTENT_LENGTH The length of the query information. Available only for POST requests. HTTP_COOKIE Returns the set cookies in the form of key-value pairs. HTTP_USER_AGENT Contains information about the ...

Read More
Showing 1–10 of 61,304 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements