Tutorial Example

WordPress Upload Python Script (.py) File – A Beginner Guide

WordPress does not allow us to upload python script file (.py) to web server defaultly. In this tutorial, we will introduce you how to upload .py files to wordpress successfully.

Upload .py file to wordpress

If you upload a .py file to wordpress, you may get a security error. Here is an example:

How to upload .py file to wordpress?

We can open our theme functions.php file, and add code below.

function my_myme_types($mime_types){
    $mime_types['py'] = 'text/x-python'; //Adding .py extension
    $mime_types['pyc'] = 'application/x-python-code'; //Adding .pyc extension
    return $mime_types;
}
add_filter('upload_mimes', 'my_myme_types', 1, 1);

Then save functions.php and refresh page that uploads media files. You can find that we can upload python script to wordpress. Here is an example:

Here are more file mime types for you to make allow wordpress upload them.

A List of Content MIME Types for Beginners – Python Tutorial