I have a code which should allow me to update the field = status, by 'delivered' this is the index.html where the button is:
<form action="/some/url/mapped/to/pedido_sub/view/">
<input type="submit" name="Aprobar" class="btn btn-primary pull-right" value="Aprobar"/>
</form>
then the views.py code is this:
def pedido_sub(request, id_pedido):
pedido = get_object_or_404(Pedido, pk=id_pedido)
if (request.method == POST) and ("Aprobar" in request.POST):
pedido.estado = 'entregado'
pedido.save()
# Send a Success Message to the User
else:
return render(request, 'index.html')
a idea is that when I press the button I update the field, but the error is:
Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/some/url/mapped/to/pedido_sub/view/?Aprobar=Aprobar
My urls.py of the app:
urlpatterns = [
url(r'^home', login_required(Pedidoapp.views.home), name='home'),
url(r'^confirmar/',login_required(Pedidoapp.views.aprobar_pedido), name='aprobar_pedido'),
url(r'^Pedido/$', login_required(Pedidoapp.views.add), name="add"),
My project urls.py:
urlpatterns = [ # Examples:
url(r'^home/', include(Pedidoapp.urls, namespace="usuario")),
url(r'^home/$', login_required(Pedidoapp.views.home), name="home"),
# url(r'^home_user/$', login_required(Pedidoapp.views.homeuser), name="homeuser"),
url(r'^add/$', login_required(Pedidoapp.views.add), name="add"), url(r'aprobar_pedido/$', aprobar_pedido, name='aprobar_pedido'),