We designed and synthesized a novel covalent organic framework (COF) by condensation polymerization of 1,3,6,8-tetrakis(4-formylphenyl)pyrene and melamine through imine bonds (represented by Py-M-COF). The basic characterizations revealed that the Py-M-COF not only exhibited an extended pi-conjugation framework, a large specific surface area (495.5 m(2) g(-1)), big pore cavities, and nanosheet-like structure but also possessed rich functional groups, such as (CC)-C-center dot, (CN)-N-center dot, (CO)-O-center dot and NH2. These features endowed the Py-M-COF with high charge carrier mobility, further improving the strong immobilization of DNA aptamer strands via pi-pi stacking interaction and electrostatic interaction. As such, the Py-M-COF-based electrochemical aptasensors are ultrasensitive in detecting different antibiotics, including enrofloxacin (ENR) and ampicillin (AMP), yielding extremely low detection limits of 6.07 and 0.04 fg mL(-1) (S/N = 3) toward ENR and AMP, respectively, along with other excellent sensing performances. This biosensing platform based on Py-M-COF has potential applications for the sensitive detection of antibiotics or other analytes by replacing the corresponding aptamers.