The invention discloses application of a diketopyrrolopyrrole derivative. The diketopyrrolopyrrole derivative has a selective complexation effect on Hg<2+>, can easily realize decomplexation and is applicable as an Hg<2+> recognition substance to preparation of a fluorescent sensor used for detecting Hg<2+> in an aqueous solution. The prepared fluorescent sensor used for detecting Hg<2+> has the characteristics of recognizability with naked eyes, high sensitivity and repeated usability, has high Hg<2+> selectivity and is free of interference by cations like Ag<+>, Pb<2+>, Cu<2+>, Cr<3+>, Mn<2+>, Fe<3+>, Co<2+>, Ni<2+>, Zn<2+>, Cd<2+> and Al<3+> in detection of Hg<2+>. The fluorescent sensor is widely applicable to the fields of environmental engineering, biological detection, etc.