Установить приложение django для клиента и защитить его исходный код или преобразовать его в исполняемый файл

У меня есть веб-приложение Django, я хочу установить его для клиента, который не хочет использовать интернет, поэтому я должен установить его локально на его ПК, Мой вопрос: что я должен сделать, чтобы защитить мой исходный код. Видя, что я должен поместить весь мой исходный код на его ПК, чтобы иметь возможность установить приложение, есть ли возможность зашифровать исходный код или преобразовать проект django в exe? Спасибо!

Это то, что я использовал раньше. Если результат компиляции Cython удовлетворяет вашим потребностям, вы можете использовать его для справки.

Структура директории:
- project_path
- xx(new_path)
  - setup.py
Выполнить команду:

Если вы шифруете всю папку, поставьте __init__.py в папке.

python setup.py build_ext -i

or 

python setup.py build_ext --inplace
Программа:
from distutils.core import setup
from Cython.Build import cythonize
import shutil, os, sys, platform

if platform.system() == 'Windows':
    splice_str = "\\"
else:
    splice_str = "/"

# https://stackoverflow.com/questions/58797673/how-to-compile-init-py-file-using-cython-on-window/58803865#58803865
# Windows need to add
from distutils.command.build_ext import build_ext
def get_export_symbols_fixed(self, ext):
    names = ext.name.split('.')
    if names[-1] != "__init__":
        initfunc_name = "PyInit_" + names[-1]  # package name
    else:
        # take name of the package if it is an __init__-file
        initfunc_name = "PyInit_" + names[-2]  # filename
    if initfunc_name not in ext.export_symbols:
        ext.export_symbols.append(initfunc_name)
    return ext.export_symbols

# replace wrong version with the fixed:
build_ext.get_export_symbols = get_export_symbols_fixed


def get_allfile(old_dir, new_dir):
    import os
    # Get the root path of the current project
    root_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), old_dir)
    print(root_dir)
    exclude_folder = [".git", ".idea", "__pycache__", "static"]
    try:
        for root, dirs, files in os.walk(root_dir):
            # if not root.endswith('__pycache__'):
            if not [i for i in exclude_folder if i in root.split(splice_str)]:
                for file in files:
                    old_file = root + splice_str + file
                    if file.endswith('.py') and not file.startswith('00'):
                        add_commnet(old_file)
                        compile_code(old_file, old_file)
                    else:
                        current_dir = root.replace(root_dir, new_dir)
                        if not os.path.exists(current_dir):
                            os.mkdir(current_dir)
                        # Copy new file
                        print(current_dir, old_file)
                        shutil.copy(old_file, current_dir + splice_str + file)
        [os.remove(root + splice_str + file) for root, dirs, files in os.walk(root_dir) for file in files if file.endswith(".c")]

    except Exception as e:
        print(e)


# compile
def compile_code(name, filename):
    setup(
        name=name,
        ext_modules=cythonize(filename),
    )


def add_commnet(filename):
    with open(filename, 'r+', encoding='utf-8')as f:
        insert_data = '# cython: language_level=3\n'
        data = f.readlines()
        if not data or data[0] != insert_data:
            data.insert(0, insert_data)
        f.seek(0, 0)
        f.writelines(data)


if __name__ == '__main__':
    print(sys.argv)
    run_parms = sys.argv[3:]
    sys.argv = sys.argv[:3]
    if len(run_parms) >= 2:
        old_file = run_parms[0]
        new_file = run_parms[1]
    else:
        old_file = 'project_path'
        new_file = os.getcwd()
    get_allfile(old_file, new_file)
Вернуться на верх