Sunday, February 28, 2016

Re: mathematical function and django connect

update my project now

my view.py code

def calc(request):
a = []
NList = []
y=0
member=0
member = request.POST.get ('member', False)
for i in range(int(member)):
input = request.POST.get ('input', False)
NList.append(int(input))
for k in NList:
if k is 1:
y = 1
elif (k > 1) and (k < 5):
y = (k - 1) + 2
a.append(y)
return render_to_response ('blog/calc.html', {'a' :a, 'member':member}, context_instance=RequestContext(request))

my urls.py
from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$',views.calc, name='calc'),
]
html code with the javascript
<body>
<form action="" method="post" name="detParameterForm">{% csrf_token %}
<fieldset class="det">
<legend>Closure Level</legend>
Number of members:<input type="text" id="member" name="member" value=""><br />
<button id="btn" onclick="addinputFields()">Button</button>
<div id="container"/>
</fieldset>
<button type="submit" value="Submit">submit</button>
</form>
<script>
function addinputFields(){
// Disable Default Action (Form Posting)
event.preventDefault();
// parseInt() - The value entered should be a number / integer
var number = parseInt(document.getElementById("member").value);
for (i=0;i<number;i++){
var input = document.createElement("input");
input.type = "text";
container.appendChild(input);
container.appendChild(document.createElement("br"));
}
}
</script>
<p>
{{ a}}
or full info
{% for sm in a %}
{{ sm }}
{% endfor %}
</p>
</body>

but not work again show me zero results,any idea ?

Τη Τρίτη, 9 Φεβρουαρίου 2016 - 9:47:30 μ.μ. UTC+2, ο χρήστης Xristos Xristoou έγραψε:
hello,


i create some python mathematical function on python idle,
i want to create website where the user import value numbers on the function
and take the results from that.
question one,how to connect my mathematical function on the django?
question two,how to connect input and output from the scipts in the website ?
the second question i ask because input and output from the function is a dynamic define from the user



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/aadbc19e-e424-4f41-8e0d-0f593b62b5e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment