TR, TH, TD was created but TABLE NOT - django

i Need understand it but not be able to.
My ClassForm (in view):
class FormContact(forms.Form):
name = forms.CharField(label='Nome', max_length=100, required=False)
subject = forms.CharField(label='Assunto', max_length=100, required=False)
message = forms.CharField(label='Mensagem', widget=forms.Textarea, required=False)
My extended Template:
{% extends 'site.html' %}
{% load static %}
{% block content %}
<form class="contato" id="contato" action="{% url 'contato' %}" method="post">
<h1>Contato</h1>
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
<script src="{% static 'js/form_contact.js' %}"></script>
{% endblock %}
Now,
in the navigator (inspector -> elements)
<form class="contato" id="contato" action="/contato/" method="post">
<h1>Contato</h1>
<input type="hidden" name="csrfmiddlewaretoken" value="???">
<label for="id_name">Nome:</label>
<input type="text" name="name" maxlength="100" id="id_name">
<label for="id_subject">Assunto:</label>
<input type="text" name="subject" maxlength="100" id="id_subject">
<label for="id_message">Mensagem:</label>
<textarea name="message" cols="40" rows="10" id="id_message"></textarea>
<input type="submit" value="Submit">
/form>
AND, in the navigator (Ctrl+U) View Code
<form class="contato" id="contato" action="/contato/" method="post">
<h1>Contato</h1>
<input type="hidden" name="csrfmiddlewaretoken" value="????">
<tr>
<th><label for="id_name">Nome:</label></th>
<td>
<input type="text" name="name" maxlength="100" id="id_name">
</td>
</tr>
<tr>
<th><label for="id_subject">Assunto:</label></th>
<td>
<input type="text" name="subject" maxlength="100" required id="id_subject">
</td>
</tr>
<tr>
<th><label for="id_message">Mensagem:</label></th>
<td>
<textarea name="message" cols="40" rows="10" required id="id_message"></textarea>
</td>
</tr>
<input type="submit" value="Submit">
</form>
My doubt is:
Why, in the Ctrl+U, was created the elements TR, TH and TD but TABLE not?
I can't understand it
It is this form same?

Related

How can I access the outer loop context value in inner loop section in Django Template

In my case, I want to access the context value which is present in the outer for loop and use(print) that value in the inner for loop section. There are two context values one for the outer loop and the other one is for the inner loop.
here is my template logic. when the condition becomes false it did not print the values that belong to the outer-loop context variable(else part of if statement not working).
<div class="panel-group" id="accordion">
{% for x in queryset %}<!--outerloop-->
<div id="collapse{{ forloop.counter }}" class="panel-collapse collapse">
<div class="panel-body">
<div>
<form action="tobeupdated" method="POST" enctype="multipart/form-data" >
{% csrf_token %}
<label>Q- <input type="text" id="ques" name="ques" value="{{x.question.question}}" readonly></label><br><br>
<img src="{{x.question.image}}" alt="" srcset="" width="700"><br><br>
{% for q2 in queryset2 %}<!--innerloop-->
{% if q2.option_id == x.option_id %}
<label>A- <input type="text" id="op1" name="op1" value="{{q2.option.option1}}" readonly><br><br>
<img src="{{q2.option1_img}}" alt="" srcset="" width="400"><br><br>
<label>B- <input type="text" id="op2" name="op2" value="{{q2.option.option2}}" readonly><br><br>
<img src="{{q2.option2_img}}" alt="" srcset="" width="400"><br><br>
<label>C- <input type="text" id="op3" name="op3" value="{{q2.option.option3}}" readonly><br><br>
<img src="{{q2.option3_img}}" alt="" srcset="" width="400"><br><br>
<label>D- <input type="text" id="op4" name="op4" value="{{q2.option.option4}}" readonly><br><br>
<img src="{{q2.option4_img}}" alt="" srcset="" width="400"><br><br>
{% else %}
<label>A- <input type="text" id="op1" name="op1" value="{{x.option.option1}}" readonly><br><br>
<label>B- <input type="text" id="op2" name="op2" value="{{x.option.option2}}" readonly><br><br>
<label>C- <input type="text" id="op3" name="op3" value="{{x.option.option3}}" readonly><br><br>
<label>D- <input type="text" id="op4" name="op4" value="{{x.option.option4}}" readonly><br><br>
{% endif %}
{% endfor %}
<label>Correct Ans- <input type="text" id="ans" name="ans" value="{{x.correct_ans}}" readonly><br><br>
<input type="hidden" id="dlevel" name="dlevel" value="{{x.question.difficulty}}">
<input type="checkbox" name="" checked>
<label>{{x.question.difficulty}}</label>
<!-- <input type="submit" id="update" value="Update" /> -->
<button type="submit" class="btn btn-primary" name="qid" value="{{x.question.id}}" >Edit</button>
<button type="submit" class="btn btn-primary" name="delete_qid" value="{{x.question.id}}" >Delete</button>
</form>
</div>
<!--Toogle Button-->
</div>
</div>
{{x.question.id}}
<!-- Button trigger modal -->
</div>
</div>
{% endfor %}
</div>
Any suggestions regarding this problem will be highly appreciated.

Using GeoLocation variables in CFSET

I'm trying to capture geolocation data and insert it into a database.
The code below is my attempt to capture the browser's longitude and latitude and save the values in two form fields. The problem is the output code generates multiple instances of the two form fields (i.e. "longitude" and "longitude"). Here's a screen shot of a single set of those fields being populated. How do I populate the rest?
Form Code:
<div class="table-responsive">
<table class="table table-1" style="color:##000000">
<tr>
<td>Tree No</td>
<td>Current Status</td>
<td>Graft Successful</td>
<td>NOT Grafted</td>
<td>Graft unsuccessful</td>
<td>Tree Died</td>
</tr>
<cfoutput query="rsTreeList" >
<tr>
<td>#TreeID#</td>
<td>#Status#</td>
<td>
<form name="form1" method="post" action="Recon_Update_Logic1.cfm?ID=#TreeID#">
<img src="images/Icons/Success.jpg" width="25" height="25" alt=""/>
<input id="latitude" name="latitude" type="text" />
<input id="longitude" name="longitude" type="hidden" />
<input name="submit" type="submit" id="Submit" value="Graft Successful">
</form>
</td>
<td>
<form name="form1" method="post" action="Recon_Update_Logic2.cfm?ID=#TreeID#">
<img src="images/Icons/NotGrafted.jpg" width="25" height="25" alt=""/>
<input id="latitude" name="latitude" type="text" />
<input id="longitude" name="longitude" type="hidden" />
<input name="submit" type="submit" id="Submit" value="NOT Grafted">
</form>
</td>
<td>
<form name="form1" method="post" action="Recon_Update_Logic3.cfm?ID=#TreeID#">
<img src="images/Icons/GraftUnsuccessful.jpg" width="25" height="25" alt=""/>
<input id="latitude" name="latitude" type="hidden" />
<input id="longitude" name="longitude" type="hidden" />
<input name="submit" type="submit" id="Submit" value="Graft Unsuccessful">
</form>
</td>
<td>
<form name="form1" method="post" action="Recon_Update_Logic4.cfm?ID=#TreeID#">
<img src="images/Icons/TreeDead.jpg" width="25" height="25" alt=""/>
<input id="latitude" name="latitude" type="hidden" />
<input id="longitude" name="longitude" type="hidden" />
<input name="submit" type="submit" id="Submit" value="Tree Dead">
</form>
</td>
</tr>
</cfoutput>
</table>
</div>
The following code attempts to populate all of the "latitude" and "longitude" elements:
<cfloop index="i" from="1" to="#rsTreeList.recordCount#">
<script>
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
}
function showPosition(position)
{
document.getElementById("latitude").value = position.coords.latitude;
document.getElementByID("longitude").value = position.coords.longitude;
}
getLocation();
</script>
</cfloop>

django allauth: redirecting for invalid passwords

I have a custom page which calls allauth signup view (custom_passcheck.html)
<form action="{% url 'account_signup' %}" method="post" class="form">
{% csrf_token %}
<BR>
<BR>
<BR>
<center>
<div class=signuponepage>
<div class=sign-up>
<div class=signup-box>
<div class="form-element email-address">
<label id="email-address-label">
<strong>
Create a password (it must be 6 characters long)
</strong>
<input type="hidden" name="username" value="{{ pemail }}">
<input type="hidden" name="email" value="{{ email }}">
<input type="text" maxlength="19" name="password1" value="" placeholder="Password">
<input type="text" maxlength="19" name="password2" value="" placeholder="Password (again)">
</label>
</div>
<div class="form-element nextstep-button">
{% buttons %}
<button type="submit" class="btn btn-primary btn-sm">
Finish {% bootstrap_icon "chevron-right" %}
</button>
{% endbuttons %}
</div>
</div>
</div>
</div>
</center>
</form>
Now, if a user puts in password less than 6 chars, it will raise an error and redirect the user to allauth signup page (/account/signup)
Question: instead of redirecting to (/account/signup), how can i redirect to the custom page (custom_passcheck.html) while preserving POST data

Django form in a table can't get right parameters

<tbody>
{% for sec in sec_list %}
<tr>
<td>{{sec.c_id_id}}.{{sec.sec_id}}</td>
<td>{{sec.title}}</td>
<td>{{sec.name}}</td>
<td>{{sec.time}}</td>
<td>{{sec.r_no_id}}</td>
<td>{{sec.cur}}/{{sec.capcity}}</td>
<td><form method="post" role="form" action="">
{% csrf_token %}
<input class="hidden" type="submit" value="{{sec.c_id_id}}.{{sec.sec_id}}" name="course" id="course">
<input class="hidden" type="submit" value="{{sec.cur}}" name="num" id="num">
<input class="hidden" type="submit" value="{{sec.capcity}}" name="limit" id="limit">
<p class="form-action">
<input type="submit" value="选课" class="btn btn-link">
</p>
</form></td>
</tr>
{% endfor %}
</tbody>
I want to use a hidden form to transfer some parameters in a table.My code is above.But when I use
request.POST.get("limit",'')
,I got a null one.How to fix it
edit your html code by replacing the type="submit" to type="hidden",
<td><form method="post" role="form" action="">
{% csrf_token %}
<input class="hidden" type="hidden" value="{{sec.c_id_id}}.{{sec.sec_id}}" name="course" id="course">
<input class="hidden" type="hidden" value="{{sec.cur}}" name="num" id="num">
<input class="hidden" type="hidden" value="{{sec.capcity}}" name="limit" id="limit">
<p class="form-action">
<input type="submit" value="选课" class="btn btn-link">
</p>
</form></td>
Shouldn't those inputs be type=hidden instead of class=hidden?
<input type="hidden" value="{{sec.capcity}}" name="limit" id="limit">
The type=submit in all of them makes no sense to me as it is supposed to be used only in submit buttons.

How to customize the input element generated by django.forms?

I'm using django.forms to generate my login/signup page, part of code is as follows:
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
<table>
<tr>
{# username is directed to email field in our model #}
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
{% if next %}
<input type="hidden" name="next" value="{{ next }}" />
{% else %}
<input type="hidden" name="next" value="{% url 'home' %}" />
{% endif %}
</form>
As you can see, the {{ form.username }} and {{ form.password }} will automatically generate an <input id="id_username" maxlength="254" name="username" type="text"> and an <input id="id_password" name="password" type="password"> respectively. But I want to add some extra attributes to these input fields, like placeholderand class. Where can I customize these?
Either manually:
<input type="text" name="{{ form.field.html_name }}" placeholder="foo" value="{{ form.field.value }}" />
Or via the widget attrs argument
https://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs
class MyForm(forms.Form):
field = forms.CharField(widget=forms.TextInput(attrs={'placehoder': 'foo', 'title': 'baz'}))
You may use django-widget-tweaks which is a very nice library for tweaking django's widget. I've used it and it's quite simple.
From their site:
{% load widget_tweaks %}
<!-- change input type (e.g. to HTML5) -->
{% render_field form.search_query type="search" %}
<!-- add/change several attributes -->
{% render_field form.text rows="20" cols="20" title="Hello, world!" %}
<!-- append to an attribute -->
{% render_field form.title class+="css_class_1 css_class_2" %}
<!-- template variables can be used as attribute values -->
{% render_field form.text placeholder=form.text.label %}
Hope this helps!