My very simple Django Form not passing value to another View

In yours template you direct form to send it to prd_btch_dtl function:

<form action={% url 'prd_btch_dtl' form.prd_btch_nbr %} method="post">

so in views.py prd_btch_dtl you need to get values from form:

def prd_btch_dtl(request, prd_btch_nbr):
"""View function for home page of site."""
acctid = 1
# prd_btch_nbr = '61210'
# Generate counts of some of the main objects

if request.method == 'POST':
    form = PrdBtchSelect(request.POST)
    if form.is_valid():
       prd_btch_nbr = int(form.cleaned_data['prd_btch_nbr'])

prd_btch_dtl = sql.product_batch_detail(prd_btch_nbr)
prd_btch_ingr_dtl = sql.product_batch_ingredient_detail(prd_btch_nbr)
prd_btch_task_dtl = sql.product_batch_task_detail(prd_btch_nbr)
acct_name = Accounts.objects.get(pk=acctid)

context = {
    'prd_btch_dtl': prd_btch_dtl,
    'prd_btch_ingr_dtl': prd_btch_ingr_dtl,
    'prd_btch_task_dtl': prd_btch_task_dtl,
    'acct_name': acct_name,
    'report_name': 'Product Batch Detail'
}

# Render the HTML template index.html with the data in the context variable
return render(request, 'reports/prd_btch_ingr_dtl.html', context=context)

you dont need to pass prd_btch_nbr in form action:

<form action={% url 'prd_btch_dtl' %} method="post">

or in declaration:

def prd_btch_dtl(request):

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top