开发者

How to make results(pass/failed) on Django

Hi All I have next models

Case, Suite I want to pass Case. For example I have next, in my html template:

<form action="" method="post">{%csrf_token%}
            <input type="submit" value="Pass">
            <input type="submit" value="Failed">
        </form>

I want to add information about pressing button into database. I have view:

def main (request):
    result = Result(id=None, result='Pass', cashe=Case.objects.get(id=3), sudite=Suite.objects.get(id=2) )
    result.save()
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        results = Result(request.POST) # A form bound to the POST data
        if results.is_valid():
         HERE WILL BE CLEANED DATA AND ETC, BUT AT 1st I WANT TO CHECK IT 
            pass
    return render_to_response('main.html', { 
                                             'suites': suites, 
                                             'cases': cases,
                                             'result': result,
                                             'host' : request.get_host()
                                             })

How to make it. I've read manual and search form works fine, but I don't know how to work with another buttons.

Anther interesti开发者_如何学编程ng thing, that If I make it through shell, data successfully added. But If reload page on localhost/main I have next:

TypeError at /main/
__init__() got an unexpected keyword argument 'case'

It's driving me crazy.

Thank you


I've found the easiest way to do this is to give your submit buttons a name - call one pass and one fail, for example. Then, when your form gets submitted, check for the key pass or fail in request.POST - the button you clicked should be there, but the other one won't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜