We provide the best constant $C$ as well as all the extremals for the generalized Poincar\'e inequality \begin{equation*} \int_{0}^{T} a|u|^p\le C\int_{0}^{T} a|u^\prime |^{p} \end{equation*} where $a\in L^\infty([0,T])$ satisfies $1 \le a(t) \le L$, $u\in W^{1,p}_0([0,T],\RR^N)$, $N\ge1$, $p>1$ and $T>0$..