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"})
相关推荐
ffqws_12 分钟前
Spring Boot入门:通过简单的注册功能串联Controller,Service,Mapper。(含有数据库建立,连接,及一些关键注解的讲解)
数据库·spring boot·后端
JaydenAI18 分钟前
[Python编程思想与技巧-01]我所理解的Python元模型
python·元宇宙·元类·元模型
程序边界19 分钟前
行标识符机制的技术演进与实践(下)——ROWID与实战应用
后端
清水白石00824 分钟前
《Python 架构师的自动化哲学:从基础语法到企业级作业调度系统与 Airflow 止损实战》
数据库·python·自动化
Justin3go24 分钟前
丢掉沉重的记忆:Codex、Claude Code 与 OpenCode 的上下文压缩术
前端·后端·架构
不懂的浪漫34 分钟前
mqtt-plus 架构解析(五):错误处理与 ErrorAction 聚合策略
java·spring boot·后端·物联网·mqtt·架构
kaico201835 分钟前
python操作数据库
开发语言·数据库·python
zhangzeyuaaa36 分钟前
Python变量的四种作用域
开发语言·python
Hommy881 小时前
【开源剪映小助手-客户端】桌面客户端
python·开源·node.js·github·剪映小助手
卷福同学1 小时前
去掉手机APP开屏广告,李跳跳2.2下载使用
java·后端·算法