MHB
MHB

Reputation: 695

html does not send post to view

I have a submit form like:

<div class="form-group">
    <div class="checkbox">
        <label for="id_active_state">
            <div class="icheckbox_square-red checked" style="position: relative;">
                <input type="checkbox" name="active_state" class="" id="id_active_state" checked=""><ins class="iCheck-helper"></ins>
            </div> active</label>
    </div>
</div>
<div class="form-group">

    <div class="button_holder">
        <button type="submit" name="submit" class="btn btn-primary" value="send">
            submit
        </button>
    </div>

</div>

and it should be handled in view:

def special_offer_edit_view(http_request):
    action_verbose_name = 'the_view'
    special_offer_id = http_request.GET.get('id')
    special_offer_obj = SpecialOffer.objects.filter(id=special_offer_id)
    for data in special_offer_obj:
        sp_obj = {'active_state': data.active_state}

    if http_request.method == 'POST':
        print('hi')

    return render(...)

it raises 503 error, and does not send "POST" method and data. what is its problem?

Upvotes: 2

Views: 44

Answers (1)

Yugandhar Chaudhari
Yugandhar Chaudhari

Reputation: 3964

Your input should be accessed by element name active_state you have given otherwise

like this will be None

special_offer_id = http_request.GET.get('id')

Your render(...) should return HttpResonse with existing template

render(http_request,"template.html",{"context" : 2})

Set DEBUG=True in settings to get the error log

Embed the html in with csrf_token

<form method="POST">
<!-- Your html here -->
{% csrf_token %}
</form>

Upvotes: 2

Related Questions