Cao Pi, formally Emperor Wen of (Cao) Wei, courtesy name Zihuan, was born in Qiao County, Pei Commandery (modern Bozhou, Anhui). He was the second son of the Chinese politician and poet Cao Cao and was the first emperor and the real founder of Cao Wei (also known as "Kingdom of Wei"), one of the Three Kingdoms.
Cao Pi was the eldest son of Cao Cao and his concubine (later wife) Princess Bian. Of all his brothers, Cao Pi was the most shrewd. Instead of studying hard or conducting military affairs, he was always in the presence of court officials in order to gain their support. He was mostly in charge of defense at the start of his career. After the defeat of Yuan Shao at Guandu, he took the widow of Yuan Shao's son Yuan Xi, Lady Zhen, as a consort, although eventually she lost his favor and was forced to commit suicide. After he became emperor, his other favorite, Guo Nüwang, became empress.
In winter 220, Cao Pi made his move for the imperial throne, strongly suggesting to Emperor Xian that he should yield the throne. Emperor Xian did so, and Cao Pi formally declined three times (a model that would be followed by future usurpers in Chinese history), and then finally accepted, ending Han Dynasty and starting a new Wei Dynasty.
The former Emperor Xian was created the Duke of Shanyang. Cao Pi posthumously honored his grandfather Cao Song and father Cao Cao as emperors, and his mother Princess Dowager Bian as empress dowager. He also moved his capital from Xu (in modern Xuchang, Henan) to Luoyang. Cao Pi continued his father's war against Liu Bei's Shu Han and Sun Quan's Eastern Wu but was unsuccessful. Unlike Cao Cao he concentrated most of his efforts on his home country, which prospered under his rule.
There were many internal conflicts during Cao Pi's rule. He demoted his brother Cao Zhi (who had contended with him the status as Cao Cao's heir) and had two of Cao Zhi's best friends executed. Allegedly, his younger brother Cao Xiong committed suicide out of fears for his brother, although this was undocumented in actual historical records.
Cao Pi also put Yu Jin to shame for his loss to Guan Yu, which caused him to become ill and die. He further restricted the roles his other brothers had in the imperial administration; in addition, unlike princes of the Han Dynasty, under regulations established by Cao Pi, Cao Wei princes had minimal authority even in their own principalities and were restricted in many ways. Many historians attribute these heavy restrictions to how Cao Pi was jealous of Cao Zhi's literary talent and Cao Zhang's military might.
Cao Pi was generally viewed as a competent, but unspectacular, administrator of his empire. He commissioned a number of capable officials to be in charge of various affairs of the empire, employing his father's general guidelines of valuing abilities over heritage. However, he was not open to criticism, and officials who dared to cricitize him were often demoted and, on rare occasions, put to death.
An immediate issue after Cao Pi became emperor in 220 was who the empress would be. Lady Zhen was his wife, but had by this point long lost favor due to a variety of reasons - chief among which was the struggle she had with a favorite concubine of Cao's, Guo Nüwang. Lady Guo used the unlikely possibility that Zhen's son Cao Rui might be biologically Yuan Xi's son to full advantage in creating conflicts between Cao Pi and Lady Zhen. Cao therefore refused to summon Lady Zhen to Luoyang after he ascended the throne but instead ordered her to remain at Yecheng, which caused Lady Zhen to be resentful. When words of her resentment reached Cao, he became angry and forced her to commit suicide. In 222, Cao created Consort Guo empress.
Empress Guo, however, was sonless. Lady Zhen's son Cao Rui was the oldest of Cao Pi's sons, but because she had been put to death and because of Cao Pi's lingering doubt as to his paternity, was not created crown prince but only the Prince of Pingyuan after Cao Pi's ascension. Cao Pi, however, did not appear to have seriously considered any other son as heir. (It might have been because the other sons were all significantly younger, although their ages were not recorded in history.) In the summer of 226, when Cao Pi was seriously ill, he finally created Prince Rui crown prince. He died soon thereafter, and Prince Rui ascended the throne.
In that period, in China, it was acceptable for someone to be a homosexual as long as their "regular duties" were fulfilled. What this means was that, as long as the male had sons to continue the family line then it was ok for them to have a male lover on top of his regular female wife. There is a listof famous emperors of China that had gay relationships. One of them is Liu Bang and another is Cao Pi.