django - what goes into the form action parameter when view requires a parameter?

后端 未结 4 1207
后悔当初
后悔当初 2020-12-13 18:30

This is what I have:

myview.py with a view that takes a parameter user:

def myview(request, user):
   form = MyForm(reques         


        
4条回答
  •  爱一瞬间的悲伤
    2020-12-13 19:19

    It should not require anything. Assuming you are at the following url:

    www.yoursite.com/users/johnsmith/
    

    Your form should be:

    At this point, you are already in myview with user johnsmith. Your view should look like the following:

    if request.method == 'POST':
        form = MyForm(request.POST)
        if form.is_valid():
            # you should be able to extract inputs from the form here
    else:
        form = MyForm()
    

提交回复
热议问题