The template method takes inorganic materials such as silicon nanoparticles, mesoporous silica and surfactants as templates, and takes carbon containing organic precursors as precursors. The template and carbon source are mixed to obtain template / carbon source composite by impregnation, and then the composite is carbonized to remove the template to obtain the pore structure, thereby producing the foamed carbon.