Skofja Loka is a medieval town near to Ljubljana and Kranj.
The history of the town started in 973 when a German emperor Oton II given this territory as a gift to bishops Freising. The town got municipal rights in 1274.
The castle was built in early 14th century along with the town fortifications. The castle was badly damaged in 1511 by an earthquake and subsequently rebuilt by bishop Filip.
In spite of many Turk rides, fires and earthquakes, Skofja Loka is nowadays the most preserved medieval town in Slovenia.