In order to effectively improve the efficiency of traditionally constructed wetlands (CW) for heavy metals treatment in sludge, constructed wetland microbial fuel cells were used for the removal of Zn and Ni in sludge, and the effect of electrode spaces on the Zn and Ni removal and the electricity generation performance were investigated. Results showed that the removal rates of Zn by CW-MFC with different electrode spacings (12cm, 15cm, 18cm and 20cm) were 84.68%, 64.56%, 66.98% and 50.23%, and the removal rates of Ni were 74.14%, 66.09%, 64.00% and 48.01%, respectively. Among them, Zn and Ni had the highest removal rate when the electrode space was 12cm, respectively, which were higher than traditional constructed wetland (CW) for 64% and 26%, respectively. In addition, under the 12cm space, the maximum output voltage and maximum power density of CW-MFC system reached 513mV and 50.76mW/m3, respectively. XPS analysis showed that the main heavy metals on the surface of the sludge were Zn and Ni, and high-valence Zn and Ni were effectively converted into low-valence substances or elemental substances. In CW-MFC system with a spacing of 12cm, the plant roots and electrodes contribute the most to the removal of Zn and Ni. In this case, the enrichment rates of Zn and Ni in the plant roots and electrodes were 23.76%, 30.97%, and 14.57%, 16.78%, respectively. This study shows that CW-MFC has a good effect on the removal of heavy metals from sludge and its power generation performance. Furthermore, it provides new ideas and references for the optimization of CW-MFC and the disposal and resource utilization of urban sludge.