Two-dimensional graphene-like materials have numerous pores, large surface areas, and other excellent properties. And two-dimensional graphene-like materials have great potential in magnetic and spintronic devices. In this paper, we intercepted a fraction of g-C3N4 and prepared it into nanoribbons. We have calculated the g-C3N4 nanoribbons by studying the electronic structure of g-C3N4 nanoribbons to determine whether they can be used as spintronic and magnetic memory devices. Because the g-C3N4 nanoribbons have a narrow band gap and more overlapping wave functions, to turn the performance of the g-C3N4 nanoribbons, it was decided to dope transition metal Fe atoms. Subsequently, we found that the doped g-C3N4 nanoribbons with Fe atoms undergo a phase transition, from semiconducting property to half-metallic property, and the magnetic property of the g-C3N4 nanoribbons is enhanced by doped Fe atoms, so the performance of the g-C3N4 nanoribbons was improved. [ABSTRACT FROM AUTHOR]