views:

123

answers:

1

I want to pass a parameter, when i click submit button.

urls.py

urlpatterns = patterns('',
    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
    (r'^home/$', 'views.home'),
    (r'^home/(?P<build>[^/]+)/$', 'views.run'),
    (r'^run/delete/$', 'views.runDelete')
)

run.html

<form name="form" method="post" action="/run/delete">
<input type="submit" value="Delete" style="margin-left:149px; width:80px; height:30px">
<table border="1"; borderColor=black>
<td></td>
<td><b>Run</b></td>
    {% for run in run_list %}
        <tr>
        <td>{{run.build}}</td>
        <td><input type="checkbox" name="var_delete" value="{{run.id}}"></td>
        <td>{{run.name}}</td>
        </tr>
    {% endfor %}
    </table>
    </form>

views.py

def run(request, build):   
    run_list = TestRun.objects.all().order_by('id')
    return render_to_response('run.html', {'run_list': run_list})

def runDelete(request):
    run_list = request.POST.getlist('var_delete')
    for run in run_list:
        run = int(run)
        TestRun.objects.get(id=run).delete()
    return render_to_response('???')

i want to show new run.html, but how can i pass run.build as an parameter to runDelete? thanks:D

A: 

What is present in run.build?

For one, you can make it an input hidden field (other than displaying how you are displaying it already) and so, the value will be present in request.POST.

You can also make it the part of the url. But may not suit for your case.

Lakshman Prasad
how to write a input hidden field?
Yuan
<input type="hidden" name="build" value="{{build}}">, from views.run pass 'build' as argument to template
Ashok
thank you very much:D
Yuan