I don’t know why while sending the variable to HTML it is showing UnboundLocalError: local variable ‘prdct’ referenced before assignment.
When I don’t pass any values from render_template() method then the code is running fine. Also the output that I’m printing using print(prdct) is also working fine.
Following is my code:
Advertisement
Answer
Your code does not create prdct
in all cases when executing the function. Only when you are entering this with request.Method = "POST"
it will work.
You cannot return something unconditionally that may not have been created:
def test(): if False: k = 42 return k test()
will throw the a different error your code – the reasons are similar.
The if
condition is not met, k = 42
is never created – so you cannot return it in all possible cases.