html forms to django
Question: > **Possible Duplicate:**  
>  [python/django adder](http://stackoverflow.com/questions/8423687/python-
> django-adder)

I am new to django and tryed to make a site that takes my number (inputted
from an of html) and add/ subtract it to an other.

So i tryed this in views.py:

    
    
    def calc(request):
        try:     
            i1 = int(request.GET['i1'])
            i2 = int(request.GET['i2'])
        except MultiValueDictKeyError:
            raise Http404()
        u = i2 + i1
        return ("answer.html", u)
    

i also showed this to some other people and they told me to make a 'link/bond'
to the html, how can i make such a link without using a database?

edit: I am very sorry guys, I started to learn django from The Djangobook and
they didn't explain it as clearly as you guys or the documentation, my sincere
apologies


Answer: Ok, I'm going to answer this simply so we can be done with this question,
which was also posted yesterday. I'm not trying to be rude here, but you
really need to do some research, read some tutorials, etc, _before_ asking a
question that doesn't really make a whole lot of sense. I'm sticking the save
logic of the form in the view so you can see what's going on.

    
    
    #forms.py
    from django import forms
    
    class AdditionForm(forms.Form):
        first_number = forms.IntegerField()
        second_number = forms.IntegerField()
    
    
    #views.py
    from django.shortcuts import render
    
    from [your_app].forms imort AdditionForm
    
    def calc(request):
        form = AdditionForm(request.POST or None)
        answer = None
        if request.method == 'POST':
            if form.is_valid():
                first_number = form.cleaned_data.get('first_number', 0)
                second_number = form.cleaned_data.get('second_number', 0)
                answer = first_number + second_number
        return render(request, 'some-file.html', {'form' : form, 'answer' : answer})
    
    
    #some-file.html
    <html>
        <head>
            <title>Simple Calculator</title>
        </head>
        <body>
            <form action="." method="post" enctype="application/x-www-form-urlencoded">
                <fieldset>
                    <ol>
                        {{ form.as_ul }}
                        <li><input type="submit" value="Add the Numbers" />
                    </ol>
                </fieldset>
            </form>
            {% if answer %}
            <p>Your answer was: {{ answer }}</p>
            {% endif %}
        </body>
    </html>
    

