Local Variable referenced before assignment

前端 未结 2 1249
挽巷
挽巷 2020-12-06 08:02

I was wondering if you guys could help. I\'m trying to do a simple view where it sends the user to the client creation form, but I keep getting this error:

相关标签:
2条回答
  • 2020-12-06 08:09

    This is what is happening:

    1. The if block is not being entered.
    2. The form variable is not defined.
    3. You then attempt to refer to the form variable in the return statement.

    As to how to fix it, that's really for you to decide. What the fix is depends on what you want your code to do in case the request method is not POST.

    0 讨论(0)
  • 2020-12-06 08:28

    You almost certainly want to de-indent this part:

    else:
        form = AddClientForm()
    

    That is, on the initial GET of the page, use a blank client form, then when the page is POSTed, use the request POST data to fill in the form object.

    0 讨论(0)
提交回复
热议问题