This paper designs a teaching mode for online ideological and political education under deep learning, designing teaching content in a structured, contextualized and activity-based way to enhance teaching effectiveness and learning experience. By mining the learning needs embedded in users’ learning behaviors, customized learning resources are provided for each student to meet the personalized learning needs of different students. It also uses knowledge-forgetting matrix decomposition technology to identify and recommend key knowledge points in teaching content, helping students master important knowledge more effectively. The teaching mode proposed in this paper performs well in resource recommendation, with an average server response time of 15.147ms, while the students’ preference time is above 0.940s, which effectively improves the educational and teaching effect of the theory and method of online ideological and political education for college students.