Oven won't stay lit

The oven won’t stay lit. The ignitor comes on. Sometimes it lights but then goes out that’s when I smell gas. I’ll open the oven and can hear the flame light up. Won’t stay lit and does not go to temperature.