On Sun, Aug 29, 2010 at 11:22 PM, Harbhag Singh Sohal <
harbhag.so...@gmail.com> wrote:

>
>
> On Sun, Aug 29, 2010 at 10:56 PM, Steve Holden <holden...@gmail.com>wrote:
>
>> On 8/29/2010 1:20 PM, Harbhag Singh Sohal wrote:
>> > i am the new user of Django, i try the tutorials of  django wesite
>> > http://docs.djangoproject.com/en/1.2/intro/tutorial01/
>> >
>> >
>> >
>> > Now i create a application in django to add two numbers, After filling
>> form.
>> > and store the values of two inputs and output after add two numbers in
>> > databases.
>> >
>> > me able to create form and database using model.py file and using
>> template,
>> > but me face problem to store the two input value in database after
>> > filling in form text box.
>> >
>> > me try use request.POST function to get the value, but me also fail to
>> > get the form values.
>> >
>> > Please suggest me how i get the value from form text fields and store
>> > in database.
>> >
>> Harbagh:
>>
>> Your question is the approximate equivalent of:
>>
>>  "I have a car, but when I try to drive it it doesn't work"
>>
>> You don't show any code, you don't give us any error messages, you don't
>> describe the failure mode at all. You simply say that you fail tp get
>> the form values and you "face a problem" in storing the information in
>> the database.
>>
>> Is it that you don't know how to write the code, or that the code you
>> have written isn't working.
>>
>>
>>
> I have written the code
> model.py
> from django.db import models
>
> class Math(models.Model):
>    input1 = models.IntegerField()
>    input2 = models.IntegerField()
>    output = models.IntegerField()
>
> Views.py file
>
> from django.template import RequestContext
> from django.shortcuts import render_to_response
> from mysite.maths.models import Math
> from django.http import Http404
> from django.shortcuts import render_to_response, get_object_or_404
> from django.http import HttpResponseRedirect, HttpResponse
> from django.template import RequestContext
>
> def index(request):
>    latest_math_list = Math.objects.all().order_by('
> id')[:5]
>    return render_to_response('maths/index.html', {'latest_math_list':
> latest_math_list})
>
> def detail(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    return render_to_response('maths/detail.html', {'math': p},
>                               context_instance=RequestContext(request))
> def results(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    return render_to_response('maths/results.html', {'math': p})
>
> def vote(request, math_id):
>    p = get_object_or_404(Math, pk=math_id)
>    try:
>        selected_input1 = p.math_set.get(pk=request.POST['input1'])
>        selected_input2 = p.math_set.get(pk=request.POST['input2'])
>    except (KeyError, Math.DoesNotExist):
>   # Redisplay the poll voting form.
>        return render_to_response('maths/detail.html', {
>            'poll': p,
>            'error_message': "You didn't fill a value.",
>        }, context_instance=RequestContext(request))
>    else:
>        selected_output = selected_input1 + selected_input2
>        selected_output.save()
>
>        return HttpResponseRedirect(reverse('mysite.maths.views.results',
> args=(p.id
>
> ,)))
>
> problem is in def vote function.
>
>
> for code:-
http://202.164.53.116/~jagdeep/mysite/maths/<http://202.164.53.116/%7Ejagdeep/mysite/maths/>


http://202.164.53.116/~jagdeep/mytemplates/maths/<http://202.164.53.116/%7Ejagdeep/mytemplates/maths/>



and also check site
http://202.164.53.116/django/maths/2/





-- 
Harbhag Singh Sohal
Website : http://harbhag.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to