For the example you posted there (two masses connected by a light inextensible rope over a frictionless pulley):
Consider the Lagrangian [tex]
L_1(x_1,x_2,\dot x_1, \dot x_2) = \tfrac12(m_1 \dot x_1^2 + m_2 \dot x_2^2) + m_1gx_1 + m_2gx_2 - T(x_1 + x_2 - l),[/tex] where [itex]x_1[/itex] and [itex]x_2[/itex] are measured vertically downwards from the center of the pulley, [itex]l[/itex] is the length of the rope less half the circumference of the pulley, and [itex]T[/itex] is a Lagrange multiplier. Obtaining the Euler-Lagrange equations shows that [itex]T[/itex] takes the role of a force directed vertically upwards and acting on both masses, which in this physical context must be the tension in the rope.
Alternatively, consider [tex]
\begin{split}<br />
L_2(x_1, \dot x_1) &= L_1(x_1, l - x_1, \dot x_1, -\dot x_1) \\<br />
&=\tfrac12 (m_1 + m_2) \dot x_1^2 + m_1gx_1 + m_2g(l - x_1),\end{split}[/tex] which is the result of eliminating [itex]x_2[/itex] and [itex]\dot x_2[/itex] from [itex]L_1[/itex] using the constraint. Note that [itex]T[/itex] does not appear in [itex]L_2[/itex].
If you want to find the tension, then you have two unknowns: the tension and the acceleration of one of the masses. Starting from [itex]L_1[/itex], obtaining the Euler-Lagrange equations for [itex]x_1[/itex] and [itex]x_2[/itex], and only then imposing the constraint [itex]x_1 + x_2 = l[/itex] gives you the two equations necessary to solve for [itex]T[/itex] and [itex]\ddot x_1 = -\ddot x_2[/itex]. Starting from [itex]L_2[/itex] only gives you a single Euler-Lagrange equation from which you can find [itex]\ddot x_1[/itex].