Way back on page 15 of this thread is this post from a long-since banned poster. Can't see if there's been any update, so I've plonked the update on the bottom
Candidates in constituencies fought by sitting Prime Ministers
1900: N/A. Prime Minister was in the House of Lords
1906: Stirling Burghs. Liberal (unopposed) [1]
Jan 1910: Fife, Eastern. Liberal, Conservative
Dec 1910: Fife, Eastern. Liberal, Conservative
1918: Caernarvon Boroughs. Liberal (Coalition coupon), Independent
1922: Glasgow, Central. Conservative, Labour, Liberal [2]
1923: Worcestershire, Bewdley. Conservative, Liberal
1924: Glamorgan, Aberavon. Labour, Liberal
1929: Worcestershire, Bewdley. Conservative, Liberal, Labour
1931: Durham, Seaham. National Labour, Labour, Communist
1935: Worcestershire, Bewdley. Conservative (unopposed)
1945: Woodford. Conservative, Independent [3]
1950: Walthamstow, West. Labour, Conservative, Liberal, Independent Labour [4]
1951: Walthamstow, West. Labour, Conservative
1955: Warwickshire, Warwick and Leamington. Conservative, Labour.
1959: Bromley. Conservative, Labour
1964: Perthshire and Kinross-shire, Kinross and West Perthshire. Conservative, Labour, SNP, Communist
1966: Lancashire, Huyton. Labour, Conservative, National Teenage Party
1970: Lancashire, Huyton. Labour, Conservative, Democratic Party, Communist
Feb 1974: Bexley, Sidcup. Conservative, Labour, Liberal, Independent [5]
Oct 1974: Lancashire, Huyton. Labour, Conservative, Liberal
1979: Cardiff, South East. Labour, Conservative, Plaid Cymru, Severnside Libertarian, Independent Socialist, Communist
1983: Barnet, Finchley. Conservative, Labour, Liberal, Ecology/Women For Life on Earth-joint, MR Loony, 6 x Independent
1987: Barnet, Finchley. Conservative, Labour, Liberal, 2 x Independent
1992: Cambridgeshire, Huntingdon. Conservative, Labour, Liberal Democrat, Liberal, Green, MR Loony, Independent Conservative, 2 x Independent, Natural Law
1997: Cambridgeshire, Huntingdon. Conservative, Labour, Liberal Democrat, Referendum, UKIP, Independent Democrat, Independent
2001: Durham, Sedgefield. Labour, Conservative, Liberal Democrat, UKIP, Socialist Labour, Rock 'n' Roll Loony, Women For Life on Earth
2005: Durham, Sedgefield. Labour, Conservative, Liberal Democrat, 6 x Independent, UKIP, National Front, Veritas, MR Loony, Senior Citizens, UK Pensioners
2010: Fife, Kirkcaldy and Cowdenbeath. Labour, SNP, Liberal Democrat, Conservative, UKIP, 3 x Independent
2015: Oxfordshire, Witney. Conservative, Labour, UKIP, Liberal Democrat, Green, National Health Action, Wessex Regionalist, Reduce Vat in Sport, Give me Back Elmo, Land Party, 2 x Independents
2017: Berkshire, Maidenhead. Conservative, Labour, Liberal Democrat, Green, UKIP, Animal Welfare, Monster Raving Loony, Christian Peoples Alliance, Just Political Party, Give me Back Elmo, 3 x Independents
[1] Prime Minister dissolved Parliament almost immediately on taking office. Previous PM was member for Manchester, East
[2] Prime Minister dissolved Parliament almost immediately on taking office. Previous PM was member for Caernarvon Boroughs - National Liberal (unopposed)
[3] Prime Minister was outgoing member for Essex, Epping
[4] Prime Minister was outgoing member for Stepney, Limehouse
[5] Prime Minister was outgoing member for Bexley