newbie question

66 views
Skip to first unread message

VMD

unread,
Mar 18, 2015, 2:12:11 PM3/18/15
to django...@googlegroups.com
New to django and web frameworks in general. The tutorial is great for database type apps but I want to solve a different problem to start with and am kinda stuck. All I want to do is allow a user to input a value(s) and return the output of a python function using that value(s). Could someone point me to an example or guide for doing this.
For example:

Accept input X, Y
Return the output of myadder(x,y)

def myadder(x,y):
    return x+y

Avraham Serour

unread,
Mar 18, 2015, 2:51:22 PM3/18/15
to django...@googlegroups.com
short - use a view

follow the tutorial, yes you will learn how to store and retrieve values from a database, and I understand that you don't need that yet but the tutorial is very brief, you won't waste your time with advanced topics you don't need

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4f1c37bd-0f91-4708-aa40-e1dd0db44e09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

VMD

unread,
Mar 18, 2015, 10:41:57 PM3/18/15
to django...@googlegroups.com
On Wednesday, March 18, 2015 at 12:51:22 PM UTC-6, Avraham Serour wrote:
short - use a view

follow the tutorial, yes you will learn how to store and retrieve values from a database, and I understand that you don't need that yet but the tutorial is very brief, you won't waste your time with advanced topics you don't need

I understand you have good intentions with your answer. I am trying not to be frustrated with it. I don't think I would call the tutorial "very brief" I have skimmed the tutorial and didn't find (notice) the answer. Why not point me to an answer to my question?

Trying not to be frustrated ;)
Thanks
VMD

Javier Guerra Giraldez

unread,
Mar 19, 2015, 11:39:45 AM3/19/15
to django...@googlegroups.com
On Wed, Mar 18, 2015 at 9:41 PM, VMD <vin...@vincentdavis.com> wrote:
> I have skimmed the tutorial and didn't find (notice) the answer. Why not
> point me to an answer to my question?


that's exactly the point. your question assumes Django works in some
specific way, and there should be a simple answer for a simple need.

but i don't think you assumptions are correct, if you knew how Django
(and frameworks in general) work, your question might be very
different, and the answer much simpler and better in general.

really, doing the tutorial is a very good investment of your time.


--
Javier

Andrew Farrell

unread,
Mar 19, 2015, 11:58:14 AM3/19/15
to django...@googlegroups.com
The other commenters are right that reading the tutorial is a good use of your time.
is the section relevant to your question.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

David Gleba

unread,
Mar 20, 2015, 11:58:23 AM3/20/15
to django...@googlegroups.com
Does part 3 of the tutorial cover how to make a form, get the values without storing them in a database, perform the arithmetic and then display the result? I didn't see that in there.

VMD

unread,
Mar 20, 2015, 12:03:51 PM3/20/15
to django...@googlegroups.com
On Friday, March 20, 2015 at 9:58:23 AM UTC-6, David Gleba wrote:
Does part 3 of the tutorial cover how to make a form, get the values without storing them in a database, perform the arithmetic and then display the result? I didn't see that in there.
 
I don't what to store them in a database. Just do the calculation. Is this explained in the tutorial?

I have been sick = brain not working well. maybe I'll get this figured out today or actually do the whole tutorial.

VMD

David Gleba

unread,
Mar 20, 2015, 1:09:57 PM3/20/15
to django...@googlegroups.com
I will try to answer your question here another way.

I searched google for: form to add two numbers


This example uses an HTML form and javascript to perform the task on the input.

You don't actually need python or django to get form input and do something with the input.

Also, I am not an expert in Django yet, but I think you can use html and javascript in views.

john

unread,
Mar 20, 2015, 1:13:40 PM3/20/15
to django...@googlegroups.com
I'm not aware that you can use javascript in views.py. In the Template
- I believe you mean.

Johnf

VMD

unread,
Mar 20, 2015, 1:32:26 PM3/20/15
to django...@googlegroups.com

On Friday, March 20, 2015 at 11:09:57 AM UTC-6, David Gleba wrote:

You don't actually need python or django to get form input and do something with the input.

My function is not as simple as adding two numbers and for various reasons I am not interested in using Javascript. I just used myadder(x,y)  as an example.

john

unread,
Mar 20, 2015, 2:42:02 PM3/20/15
to django...@googlegroups.com
Maybe another way to reply to your question is to break down how it would work normally.
There are two sides of this question - the server side and the client side.

In general client side stuff is done in javascript.
Server side requests are done in python.

So you have to decide where you want this to happen.  If you chose the server side realize that a round trip has to occur.  This can be done and was done often but not normally used when dealing with direct user input (javascript is used) on the client side (in the browser).  You can in fact create a button that retrieves the data (executes a view function) and then returns a new view.  But that is very old school and normally not used.  You might want to look at how the django forms works under the hood and use similar code.

That said, the above is not the norm of today.  Within your template you add div id's that relate to javascript code.  When the action occurs the javascript is run (all on the client side) saving a round trip.  Today's javascript is able to retrieve data (execute a python function via a view), display data, insert new objects, etc..  So of course most use the best tool for the job.

Johnf

Vincent Davis

unread,
Mar 20, 2015, 3:49:38 PM3/20/15
to django...@googlegroups.com
On Friday, March 20, 2015, john <jo...@jfcomputer.com> wrote:
Maybe another way to reply to your question is to break down how it would work normally.
There are two sides of this question - the server side and the client side.

In general client side stuff is done in javascript.
Server side requests are done in python.

So you have to decide where you want this to happen.  If you chose the server side realize that a round trip has to occur.  This can be done and was done often but not normally used when dealing with direct user input (javascript is used) on the client side (in the browser).  You can in fact create a button that retrieves the data (executes a view function) and then returns a new view.  But that is very old school and normally not used.  You might want to look at how the django forms works under the hood and use similar code.

The Python functions I wish to execute use numpy and other Python packages I would like like to convert to JavaScript.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/GjgA-U6-CQc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/550C69C3.2030605%40jfcomputer.com.

For more options, visit https://groups.google.com/d/optout.


--
Sent from mobile app.
Vincent Davis
720-301-3003

Tom Lockhart

unread,
Mar 20, 2015, 5:18:25 PM3/20/15
to django...@googlegroups.com
> The Python functions I wish to execute use numpy and other Python packages I would like like to convert to JavaScript.

As has been suggested, the tutorial is where you want to start. By the time you finish part 4 you will have a good idea how to bypass references to a data model and use forms and views to call something in numpy and return results.

Trying to skip the tutorial just means that you will be missing information required to be comfortable starting with Django. We pretty much all started there and do not regret it.

hth

- Tom

Reply all
Reply to author
Forward
0 new messages