Potassium/sodium poly(heptazine imide) (K,Na-PHI) nanoparticles were found to possess peroxidase-like activity for the first time. In the presence of hydrogen peroxide (H 2 O 2 ), K,Na-PHI nanoparticles can produce hydroxyl radicals, oxidizing 3,3′,5,5′-tetramethylbenzidine (TMB) to form blue-oxidized TMB. Based on the property of K,Na-PHI nanoparticles, a colorimetric biosensor was developed to detect Escherichia coli O157:H7 (E. coli O157) selectively. In the biosensor, K,Na-PHI nanoparticles were employed as a peroxidase mimic and an aptamer as a recognition element. Bacteria can enhance the peroxidase-like activity of dualaptamer modified K,Na-PHI (aptamer 1,2 −K,Na-PHI) because they can capture aptamer 1,2 −K,Na-PHI and TMB, increasing the local concentrations of aptamer 1,2 −K,Na-PHI and their substrate TMB, promoting the formation of oxidized products of TMB in the catalytic system. In the biosensor, calcium peroxide was utilized to provide a source of H 2 O 2 due to its long shelf life and safe handling properties, making the biosensor convenient for on-the-spot detection, especially when long-term storage is required. Furthermore, a portable device costing $122.8 was self-designed to increase the convenience of the biosensor in on-site detection, averting the need for expensive laboratory equipment and enabling even nonexperts to use it effectively. The biosensor exhibited a limit of detection of 85 cfu•mL −1 and the detection process took 16 min. Its feasibility was verified by analyzing E. coli O157 in egg white, tofu, and soybean milk samples, with recoveries ranging from 94.1 to 110%. Therefore, the biosensor holds great potential for the on-the-spot detection of bacteria in actual food samples.