--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b9267697-b28e-4a03-af7c-88fd384cc72b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1d0bb319-dbcb-4193-b646-0640225414c1%40googlegroups.com.
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3db82847-7e0b-4194-909f-270f9bc2b3c8%40googlegroups.com.
total_inputs= int(input("number of numbers to input: "))
for i in range (total_inputs)
Num = input("Enter a number: ")
NList.append(int(Num))
..................................
progress
.................................
result1=result
result2=listresult
print(result1)
print(result2)
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2903b19d-aa7d-41ba-abcb-6f1aada7f9f4%40googlegroups.com.
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e168ac17-6786-487a-af7c-30089b5b0798%40googlegroups.com.
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9a0759fa-1cc0-4bdc-89f0-0f407c49c944%40googlegroups.com.
hello,i create some python mathematical function on python idle,i want to create website where the user import value numbers on the functionand 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
from django.shortcuts import render_to_response
def calc(request):
a = []
NList = []
y=0
nums = request.POST['num']
total_inputs = request.POST['total']
for i in range(total_inputs):
NList.append(int(num) for num in nums.split(','))
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,
})
urlpatterns = [
url(r'^$',views.calc, name='calc'),
]
<form action="" method="POST">
Number of number: <input type="text" name="num" value="Number">
Enter a value: <input type="text" name="total" value="Total value">
<button type="submit" value="Submit">
</form>
and i take that error
MultiValueDictKeyError at /
"'num'"
nums = request.POST['num']
if 'nums' in request.POST:
nums = request.POST['nums']
else:
nums = False
CSRF verification failed. Request aborted
Reason given for failure:
CSRF token missing or incorrect.
In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
request
to the template's render
method.{% csrf_token %}
template tag inside each POST form that targets an internal URL.CsrfViewMiddleware
, then you must use csrf_protect
on any views that use the csrf_token
template tag, as well as those that accept the POST data.You're seeing the help section of this page because you have DEBUG = True
in your Django settings file. Change that to False
, and only the initial error message will be displayed.
You can customize this page using the CSRF_FAILURE_VIEW setting.
i find solution for that errorif i change request to :if 'nums' in request.POST:
nums = request.POST['nums']
else:
nums = False
now i have else error and i think the code in my html form is wrong (inside the form i copy paste {% csrf_token %}) and again nothingForbidden (403)
CSRF verification failed. Request aborted
place csrf on my code
<form action="" method="POST">{% csrf_token %}
Number of number: <input type="text" name="nums" value="Number">
Enter a value: <input type="text" name="total_inputs" value="Total value">
<button type="submit" value="Submit">
</form>
This inspection highlights form elements without required associated
label (WCAG
2.0: H44) or title attribute (WCAG
2.0: H65) and provides the ability to create a new label or add an
attribute.
place csrf on my code<form action="" method="POST">{% csrf_token %}
Number of number: <input type="text" name="nums" value="Number">
Enter a value: <input type="text" name="total_inputs" value="Total value">
<button type="submit" value="Submit">
</form>and the background color from input is a differend and i take that messageThis inspection highlights form elements without required associated label (WCAG 2.0: H44) or title attribute (WCAG 2.0: H65) and provides the ability to create a new label or add an attribute.
--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb2f0706-390a-4164-aad8-6c2777df68f0%40googlegroups.com.
<form action="" method="POST">{% csrf_token %}
Number of number: <input type="text" name="num" value="Number"/>
Enter a value: <input type="text" name="total_input" value="Total value"/>
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">calc</button>
</div>
</form>
<p>
<div>
{{ a }}
or full info
{% for sm in a%}
{{ sm }}
{% endfor %}
</div>
</p>
i find it,just add return render_to_response('blog/calc.html', {'a' :a},context_instance=RequestContext(request))
and dont show me that error,but not work againnow if i touch calc button just reload dont show me error dont show me results only clear numbers why ?
<form action="" method="POST">{% csrf_token %}
Number of number: <input type="text" name="num" value="Number"/>
Enter a value: <input type="text" name="total_input" value="Total value"/>
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">calc</button>
</div>
</form>
<p>
<div>
{{ a }}
or full info
{% for sm in a%}
{{ sm }}
{% endfor %}
</div>
</p>
the problem in the html form we need to change second input to take multiple values,for example first input take a numberand the second input take many numbers..if the first number = 2 then take second input two numbers,two fields for input i try this but not workorm action="" method="POST">{% csrf_token %}Number of number: <input type="integer" name="total_inputs" value="Number"/><button type="submit" class="btn btn-default">calc</button>{% for i in total_inputs %}Enter a value: <input type="integer" name="num" value="Total value"/><button type="submit" class="btn btn-default">calc</button>{% endfor %}</form>show me error in the {% for i in total_inputs %}
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 ?
update my project nowmy view.py codedef 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))
update my code khow i feel so close but not work again hahaha to many problems. I want to write a django code which takes a number and a list of numbers from the website as user input and and then export a list with results. but if i run my app don't show me results from the progress in html template, i can only input details if i push second button just reload the page and not show me results.
I have written following code but it doesn't show me the results:
views.py
def calc(request): NList=[] num=0 a=[] y=0 c=0 total=0 num = request.POST.get ('num', False) if request.method=='POST' and 'btnform1' in request.POST: b='1'.zfill(int(num)) e=b[::-1] c=int(e) #num=int(num) if request.method=='POST' and 'btnform2' in request.POST: for i in range(int(num)): total = request.POST.get ('total', False) NList.append(int(total)) for k in NList: if k == 1: y=1
elif (k > 1) and (k < 5):
y = k+1000 a.append(y) return render_to_response ('blog/calc.html', {'a' :a,'num':num,'c':c,'y':y,'total':total,'NList':NList},context_instance=RequestContext(request))
html form
form id="form1" action="" method="POST">{% csrf_token %} <div>
Number of number: <input type="text" name="num" value="Number"/>
<div> <button type="submit" name="btnform1">count</button> </div> </div> <p> {{num}} </p> </form> <form id="form1" action="" method="POST">{% csrf_token %} <div> {% for i in c|make_list %}
Enter a value: <input type="text" name="total" value="Total value">
{% endfor %} <div> <button type="submit" name="btnform2">final</button> </div> </div> </form>
<p> {{ a}} or full info {% for sm in a %} {{ sm }} {% endfor %} </p>
urls.py
url(r'^$',views.calc, name='calc'),
this is a example if if the first input is num=4 then the script create 4 html inputs field(to user input second number list total) but if i click final button dont show me resust(a=output).
for i in range(int(num)):
total = request.POST.get ('total', False)
NList.append(int(total))