Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 22, 2010 13:31:36

Brian C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Calling a Method from a Form


Good Day,

As a part of a project I want to create a single page that has a number
of different utilities on it. One of those is a dice roller. Ultimately
I'd like to be able to type in the number of dice and number of sides,
click a button, and return the result on the page.

I understand you cannot pass arguments from a template without creating
custom tags (I think). So, ignore that aspect for now.

For now, if someone could just point me in the right direction on how to
call a method from a template and return a result.

Do I want to create a view as such (assume I have a Class for making
dice rolls):

def Dice_Roll(request):
roll = Roll(3, 8)
total = roll.output()
return render_to_response('utils/diceroll.html', {'total': total})

And call it from the template?
Or, am I going about this all wrong since this page doesn't have dynamic
or database data? Would a static HTML page work better?

Ah-ha! I see I should use Flatpages, most likely. But, I'm not sure that
solves my problem since it would still use templates and would still
have to call a method.

Thanks, and hope this wasn't too rambling,
Brian



--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 23, 2010 14:57:10

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Calling a Method from a Form


Brian

The short answer is: you need to create a form where you input
* no. of dice
* no. of sides
and then process that POSTed data.

The longer answer is <gentleness_mode_on> that you seem to be confused
about a number of basic concepts on Django and web apps. I'd
recommend working through The Django Book; Chapter 7 on Forms (http://
www.djangobook.com/en/2.0/chapter07/) has some examples you could
adapt for your specific problem. But, you *really* need to start from
Chapter 1 so you have grasped the core concepts. I speak from
personal experience - its an excellent read.<gentleness_mode_off>

Hope this helps!
Derek


On Dec 6, 3:48 pm, Brian Callies <br...@gibbous.org> wrote:
> Good Day,
>
> As a part of a project I want to create a single page that has a number
> of different utilities on it. One of those is a dice roller. Ultimately
> I'd like to be able to type in the number of dice and number of sides,
> click a button, and return the result on the page.
>
> I understand you cannot pass arguments from a template without creating
> custom tags (I think). So, ignore that aspect for now.
>
> For now, if someone could just point me in the right direction on how to
> call a method from a template and return a result.
>
> Do I want to create a view as such (assume I have a Class for making
> dice rolls):
>
> def Dice_Roll(request):
>     roll = Roll(3, 8)
>     total = roll.output()
>     return render_to_response('utils/diceroll.html', {'total': total})
>
> And call it from the template?
> Or, am I going about this all wrong since this page doesn't have dynamic
> or database data? Would a static HTML page work better?
>
> Ah-ha! I see I should use Flatpages, most likely. But, I'm not sure that
> solves my problem since it would still use templates and would still
> have to call a method.  
>
> Thanks, and hope this wasn't too rambling,
> Brian

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 25, 2010 12:18:08

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Calling a Method from a Form


On Mon, 2010-12-06 at 07:48 -0600, Brian Callies wrote:
> As a part of a project I want to create a single page that has a
> number
> of different utilities on it

did you really post this on the 6th of the month or is your system clock
b0rked?
--
regards
Kenneth Gonsalves

--
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 athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 19th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support