# How to pass number input model data between two templates/views?

**URL:** <https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846>\
**Category:** Using Django\
**Created:** [July 19, 2021, 6:18am UTC](https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846 "2021-07-19T06:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moppi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moppi/32/5211_2.png) [@Moppi](https://forum.djangoproject.com/u/Moppi)\
**Post date:** [July 19, 2021, 6:18am UTC](https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846/1 "2021-07-19T06:18:02Z")

</div>

I’m trying to create a primitive online store functionality, and I want the end user to be able to input the number of items they want to order in one “front page” view and display that data in a second “basket” view. Should I just rebuild my code using forms, or is it possible to do this in default Django code? Here is the code for my current (unsuccessful) attempt: am I on the right track?

Django models page that gives context for the templates:

class Product(models.Model):  
product\_text = models.CharField(max\_length=200)  
price = models.IntegerField(default=5)  
orderedamount = models.IntegerField(default=0)  
stock = models.IntegerField(default=10)  
def **str** (self):  
return self.product\_text

Views page:

def orderscreen(request):  
product\_list = Product.objects.all()  
context = {  
‘product\_list’: product\_list,  
}  
return render(request, ‘orderscreen.html’, context)

def basket(request):  
product\_list = Product.objects.all()  
for p in product\_list:  
context = {  
‘orderedamount’: p.orderedamount,  
}  
return render(request, ‘basket.html’, context)

First “front page” view template:

\<!doctype html\>

 Products: {% if product\_list %} 
 {% for p in product\_list %} - {{p.id}}. {{ p.product\_text }}: {{ p.price }}€ 
 {% endfor %} 
 {% endif %}

Second “basket” view:

\<!doctype html\>

 Current order: {% if product\_list %} 
 {% for p in product\_list %} - {{ p.product\_text }}: 
 {% endfor %} 
 {% endif %}

---

<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:** [July 19, 2021, 11:27am UTC](https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846/2 "2021-07-19T11:27:47Z")

</div>

First note: When you post code snippets here, please insert them between lines containing only 3 backticks - ```. (Make sure you use the backtick - ` and not the apostrophe - '.) That means you would have one line with the 3 backticks, your code, and then one more line with just the 3 backticks. That allows this forum software to format your code nicely:

````auto
# The line above this is just ```
def function(parm):
    return parm
# The line after this is just ```

````

If you want, you can edit your post to put the backticks before and after each of the code blocks you’ve posted - that’ll make it all easier for everyone to read.

> [@Moppi](#):
>
> Should I just rebuild my code using forms, or is it possible to do this in default Django code?

Using forms _is_ “default Django code”. That’s part of what makes Django such a usable system. You can get started without using them, but if you work on anything other than a “toy” project, you’ll find that you’re doing a lot of work that forms would do for you.

If you haven’t already done so, I always recommend people start with working their way through either (or both!) of the [Official Django Tutorial](https://docs.djangoproject.com/en/3.2/intro/tutorial01/) and the [Django Girls Tutorial](https://tutorial.djangogirls.org/en/). There’s a lot of useful information contained in them demonstrating how the different Django components all work together as an effective system.

Beyond that, you might also want to review [Working with forms](https://docs.djangoproject.com/en/3.2/topics/forms/#working-with-forms).

---

<div class="post-metadata">

**Author:** ![Moppi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/moppi/32/5211_2.png) [@Moppi](https://forum.djangoproject.com/u/Moppi)\
**Post date:** [July 22, 2021, 5:48am UTC](https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846/3 "2021-07-22T05:48:56Z")

</div>

I’d read the official tutorial already, so I just assumed that whatever was covered in that was the default way of doing things. Thanks for putting me on the right track. I can’t seem to be able to edit the OP anymore, though.

---

<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:** [July 22, 2021, 11:54am UTC](https://forum.djangoproject.com/t/how-to-pass-number-input-model-data-between-two-templates-views/8846/4 "2021-07-22T11:54:50Z")

</div>

The tutorial is just an introduction to help get you started. There are _many_ features within Django not covered within it, which is one reason why I also recommend the [Django Girls Tutorial](https://tutorial.djangogirls.org/en/).

Beyond that, the [What’s next?](https://docs.djangoproject.com/en/3.2/intro/tutorial07/#what-s-next) paragraph at the end of page 7 provides a link to the [What to read next](https://docs.djangoproject.com/en/3.2/intro/whatsnext/#what-to-read-next) page.
