django后台管理配置教程

最近用django开发后台管理系统,为了让后台界面更好看,更专业,您可以采用以下方法:

  1. 下载源代码
bash 复制代码
pip download simplepro -d ./
  1. 采用压缩工具解压源代码

  2. 加密文件转化,脚本如下:

python 复制代码
import lzma,base64
import glob

import os


def show_files(base_path, all_files=[]):
    file_list = os.listdir(base_path)
    # 准备循环判断每个元素是否是文件夹还是文件,是文件的话,把名称传入list,是文件夹的话,递归
    for file in file_list:
        # 利用os.path.join()方法取得路径全名,并存入cur_path变量,否则每次只能遍历一层目录
        cur_path = os.path.join(base_path, file)
        # 判断是否是文件夹
        if os.path.isdir(cur_path):
            show_files(cur_path, all_files)
        else:
            if not file.endswith('.py'):
                continue
            else:
                all_files.append(cur_path)
    return all_files


list_dirs = show_files("../simplepro/")
for fn in list_dirs:
    lines = open(fn, "r", encoding="utf-8").read()
    if "exec(lzma.decompress" in lines:
        encode_fn = fn
        lines = open(encode_fn, "r", encoding="utf-8").readlines()
        f = open(encode_fn, "w", encoding="utf-8")
        for line in lines:
            if line.strip().startswith("exec("):
                print(line)
                str_data = line.strip().replace("exec(lzma.decompress(base64.b64decode(b'", "").replace("')))", "")
                code = base64.b64decode(str_data)
                data = lzma.decompress(code)
                f.write(data.decode())
                print(data.decode())
        f.close()
  1. so文件还原,脚本如下:
python 复制代码
# -*- coding: utf-8 -*-
import os
import struct
import rsa

so_file = open("../simplepro/" + '.core.so', 'rb')
buffer = so_file.read(2)
r, = struct.unpack('h', buffer)
buffer = so_file.read(r)
pri = buffer
strs = bytearray()
while True:
    temp = so_file.read(4)
    if len(temp) == 0:
        so_file.close()
        break
    size, = struct.unpack('i', temp)
    d = so_file.read(size)
    privkey = rsa.PrivateKey.load_pkcs1(pri)
    strs.extend(rsa.decrypt(d, privkey))

# data = compile(strs.decode(encoding='utf8'), '<string>', 'exec')

print(strs.decode(encoding='utf8'))

f_w = open("../simplepro/" + '.core.so.py', 'w', encoding="utf-8")

f_w.write(strs.decode(encoding='utf8'))
f_w.close()
  1. 注释py文件编译相关代码,`apps.py`,注释部分如下:
python 复制代码
import logging

from django.apps import AppConfig
from django.conf import settings


class ProConfig(AppConfig):
    name = 'simplepro'

    def ready(self):
        log = logging.getLogger()
        
        if 'simplepro.middlewares.SimpleMiddleware' not in settings.MIDDLEWARE:
            settings.MIDDLEWARE.append('simplepro.middlewares.SimpleMiddleware')
            
            log.warning(
                """Configuration error: Please add `simplepro.middlewares.SimpleMiddleware` to settings.MIDDLEWARE
                See Documentation: https://www.noondot.com/docs/simplepro/guide/project_config.html""")
        
        from simplepro import utils
        utils.init_permissions()

    
    def ready(self):
        log = logging.getLogger()
        
        if 'simplepro.middlewares.SimpleMiddleware' not in settings.MIDDLEWARE:
            settings.MIDDLEWARE.append('simplepro.middlewares.SimpleMiddleware')
            
            log.warning("Configuration error: Please add `simplepro.middlewares.SimpleMiddleware` to settings.MIDDLEWARE See Documentation: https://www.mldoo.com/docs/simplepro/setup.html")
        
        # from simplepro import utils
        # utils.init_permissions()
        # try:
        #     import py_compile
        #     import os
        #     import simplepro
        #     root = os.path.dirname(__file__)
        #     cf = os.path.join(root, f'.compile_{simplepro.get_version()}')
        #     if not os.path.exists(cf):
        #         for root, dirs, files in os.walk(root):
        #             for f in files:
        #                 path = os.path.join(root, f)
        #                 suffix = os.path.splitext(path)[1]
        #                 if suffix == ".py":
        #                     py_compile.compile(path, cfile=path + 'c')
        #                     os.remove(path)
        
        #         s = open(cf, 'w')
        #         s.write('1')
        #         s.close()
        
        # except Exception as e:
        #     print("SimplePro在编译文件时出错,请检查目录是否有访问权限")
        #     print(e)
    
  1. `handlers.py`里面的so文件部分替换为`.core.so.py`里面的代码

  2. 修改路径`simplepro/static/admin/simplepro/70/pkg.js`里面的代码

python 复制代码
s=p}while(true)switch(s){case 0:g=t.N
f=A.dT(["host",window.location.hostname,"state",Date.now(),"secretKey",$.dG().aD("getSecretKey")],g,t.z)
e=new A.al("")
d=A.fJ(e,null)
d.M(f)
i=e.a
n=window.atob("L2xhYmVsL3Bhc3Nwb3J0Lw==")+window.btoa(i.charCodeAt(0)==0?i:i)
A.o(n)
p=4
s=7

"L2xhYmVsL3Bhc3Nwb3J0Lw==":该字符串是采用base64加密的秘钥获取url,这里我替换为自己的秘钥获取地址。base64加密解密地址如下:https://base64.us/

  1. 制定秘钥获取接口
python 复制代码
from django.contrib import admin
from django.urls import path, include, re_path
from . import views


urlpatterns = [
    path('passport/<str:secret_key>', views.Passport.as_view(), name='passport'),
]
python 复制代码
from django.shortcuts import render
from django.views import View
from django.http import HttpResponseRedirect
import json
import os
from django.http import HttpResponse
from django.http import JsonResponse



# Create your views here.
class Passport(View):

    def get(self, request, scret_key):
        return JsonResponse({"code":"200","message":"success"})
相关推荐
yousuotu2 小时前
基于Python实现亚马逊销售数据分析与预测
开发语言·python·数据分析
L Jiawen2 小时前
【Golang基础】基础知识(上)
开发语言·后端·golang
m0_462605222 小时前
第N11周:seq2seq翻译实战-Pytorch复现
人工智能·pytorch·python
qq_393060472 小时前
在WSL2的Jupyter中正确显示中文字体seaborn覆盖plt的问题
ide·python·jupyter
laocooon5238578862 小时前
对传入的 x , y 两个数组做折线图, x 对应 x 轴, y 对应 y 轴。并保存到 Task1/image1/T2.png
python·numpy·pandas·matplotlib
羽飞2 小时前
GCC ABI炸弹
linux·c++·python
卜锦元2 小时前
Golang后端性能优化手册(第四章:异步处理与消息队列)
开发语言·后端·docker·容器·性能优化·golang·团队开发
JH灰色2 小时前
【大模型】-AutoGen Studio的搭建
python·语言模型
趁月色小酌***2 小时前
JAVA 知识点总结3
java·开发语言·python