# redirect to a page based on selection from a dropdown menu in django

**URL:** <https://forum.djangoproject.com/t/redirect-to-a-page-based-on-selection-from-a-dropdown-menu-in-django/14055>\
**Category:** Getting Started\
**Created:** [May 31, 2022, 6:15pm UTC](https://forum.djangoproject.com/t/redirect-to-a-page-based-on-selection-from-a-dropdown-menu-in-django/14055 "2022-05-31T18:15:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daddypastor](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/daddypastor/32/8320_2.png) [@Daddypastor](https://forum.djangoproject.com/u/Daddypastor)\
**Post date:** [May 31, 2022, 6:15pm UTC](https://forum.djangoproject.com/t/redirect-to-a-page-based-on-selection-from-a-dropdown-menu-in-django/14055/1 "2022-05-31T18:15:25Z")

</div>

views.py

```auto
def initiat_payment(request):
	if request.method == "POST":
		payment_form = forms.PaymentForm(request.POST)
		if payment_form.is_valid():
			payment = payment_form.save()
			render(request, 'checkout.html', {'payment_form':payment_form})
	else:
		payment_form = forms.PaymentForm()
	total_amt=0
	if 'cartdata' in request.session:
		for p_id,item in request.session['cartdata'].items():
			total_amt+=int(item['qty'])*float(item['price'])
		render(request, 'checkout.html',{'cart_data':request.session['cartdata'],'totalitems':len(request.session['cartdata']),'total_amt':total_amt})	
	return render(request, 'checkout.html', {'payment_form':payment_form,'total_amt':total_amt})		

```

models.py

```auto
PAYMENT_OPTIONS=(('Cash','Cash On Delivery'),('Transfer','Direct Bank Transfer'),('Paystack','Pay Online [Secured]'))       
        
class Payment(models.Model):
    ref = models.CharField(max_length=30)
    customer = models.CharField(max_length=300, null=True)
    Shipping_address = models.CharField(max_length=200)
    Hostel_name = models.CharField(max_length=50)
    amount=models.CharField(max_length=100)
    Payment_option= models.TextField(choices=PAYMENT_OPTIONS, default='Cash')
    date_created = models.DateTimeField(default=now)
    verified = models.BooleanField(default=False, null=True)

```

forrms.py

```auto
class PaymentForm(forms.ModelForm):
	def __init__ (self, *args, **kwargs):
		super(). __init__ (*args, **kwargs)
		self.fields["Payment_option"].widget.attrs.update({
			'required':'',
			'class':"checkout __payment__ detail",
			})
	class Meta:
		model=Payment
		fields=('amount','Payment_option','customer')
type or paste code here

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [May 31, 2022, 6:59pm UTC](https://forum.djangoproject.com/t/redirect-to-a-page-based-on-selection-from-a-dropdown-menu-in-django/14055/2 "2022-05-31T18:59:15Z")

</div>

More details please. What _exactly_ do you want to have happen?

For example, do you want the selection from the menu to _immediately_ retrieve a specific page, or is this menu selection to take effect when the form is submitted?

If the latter, what do you want to have happen if the form is invalid?

Any other details or context around this that you can supply would be helpful.
