I am new bootstrap & flask.
I am getting response from flask api of 20 rows & displaying using bootstrap card like this -
<div class="row">
{% for item in data %}
<div class="card" style="width: 25rem;">
{% if item[6] == '' or item[6] == ' ' %}
<img src='static/pic_not_avl.png' class="card-img-top" alt="pic"><i class="bi bi-person-circle"></i></img>
{% else %}
<img src='static/{{item[6]}}' class="card-img-top" alt="pic"><i class="bi bi-person-circle"></i></img>
{% endif %}
<div class="card-body">
<h5 class="card-title text-center">{{item[0]}}</h5>
<p class="card-text text-center">{{item[7]}}</p>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item"><strong>State : </strong>{{item[1]}}</li>
<li class="list-group-item"><strong>Salary : </strong>{{item[2]}}</li>
<li class="list-group-item"><strong>Grade : </strong>{{item[3]}}</li>
<li class="list-group-item"><strong>Room : </strong>{{item[4]}}</li>
<li class="list-group-item"><strong>Telnum : </strong>{{item[5]}}</li>
</ul>
<div class="card-body text-center">
<button type="button" class="btn btn-primary" data-toggle="modal"
data-target="#updateModal">Update</button>
<!-- <button type="submit" class="btn btn-danger">Delete</button> -->
<a class="btn btn-danger" href="/deleteDatail?dname={{item[0]}}" role="button">Delete</a>
</div>
</div>
{% endfor %}
</div>
Now i want to delete a card (one data) on button click.
tried like this -
<a class="btn btn-danger" href="/deleteDatail?dname={{item[0]}}" role="button">Delete</a>
But I am getting error Method not allowed
How can I resolve this?
/deleteDatail?dname={{item[0]}} implies a GET call to your flask route. The error Method not allowed means your route does not support a GET. You have to do something like
#app.route("/deleteDetail/")
def deleteDetail():
dname = request.values.get("dname", None)
or you can do
#app.route("/deleteDetail/", methods = ["GET", "POST"])
def deleteDetail():
if request.method == 'POST':
dname = request.values.get("dname", None)
What I have:
What I want:
I would like to have the input centered on the page and have the label sit to the left of it using bootstrap 4 if possible. I think I might need to offset or pull the columns, but it seems justify-content center ignores any pull or offset class.
HTML (Django):
<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{% for field in form %}
<div class="row my-4 justify-content-center">
<div class="col-2 float-right text-right">
{{ field.label }}
</div>
<div class="col-4 float-left">
<div class="accountFieldWrapper">
{{ field|add_class:"form-control w-100" }}
</div>
</div>
</div>
{% endfor %}
<div class="row my-4 justify-content-center">
<button class="primaryAction btn btn-dark" type="submit">{% trans "Sign In" %}</button>
</div>
<div class="row my-4 justify-content-center">
<a class="button secondaryAction" href="{% url 'account_reset_password' %}">{% trans "Forgot Password?" %}</a>
</div>
</form>
I have a bootstrap 4 card with a button at the end that is a form button with a POST method and url attached to it. How can I align this button to the bottom of the card? Here is my current code, which, if used with a non-form button, would work just fine. You can see that I have d-flex and flex-column in the card-body as well as mt-auto on the button as suggested by Bootstrap - align button to the bottom of card
div class="container">
<div class="card-deck mb-3 mt-4 text-center">
{% for object in object_list %}
<div class="card mb-4 box-shadow">
<div class="card-header">
<h4 class="my-0 font-weight-normal">Stuff</h4>
</div>
<div class="card-body d-flex flex-column">
{% if Stuff == 'Stuff' %}
<h3 class="card-title pricing-card-title">Stuff</h3>
{% else %}
<h3 class="card-title pricing-card-title">Stuff</h3>
{% endif %}
{% if Stuff != 'Stuff' %}
<small>Stuff</small>
<small>{{ Stuff }} Stuff</small>
{% endif %}
{% if Stuff != 'Stuff' %}
<ul class="list-unstyled mt-3 mb-4">
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
<li><strong>Stuff</strong></li>
<li>Stuff</li>
{% if Stuff == 'Stuff' %}
<li>Stuff</li>
{% endif %}
</ul>
{% else %}
<ul class="list-unstyled mt-3 mb-4">
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
<li>Stuff</li>
</ul>
{% endif %}
<form method="POST" action="{% url 'Stuff' %}">
{% csrf_token %}
<div class="form-group">
<div class="row d-flex justify-content-center">
<div class="col-5">
<button type="submit" class="btn btn-info btn-md btn-block login-button mt-auto">Stuff</button>
</div>
</div>
</div>
<!-- <button class="btn btn-warning">Stuff</button> -->
<input type="hidden" name="Stuff" value="{{ Stuff }}">
</form>
</div>
</div>
{% endfor %}
</div>
</div>
I hope that I am understanding you the right way, but what if you add this to the CSS:
.card-body{
padding-bottom: 0px;
}
The button will be closer to the bottom of the card.
Solved it by using class="mt-auto" on the form section. This question: bootstrap card buttons and input text aligned bottom
says that anything under the mt-auto gets bottom-aligned.
I am in process of writing UpdateView Class form , I am using inlineformset_factory to get ForignKey objects and its works , my issue is that i would like to iterate all ForignKey with HTML for displaying all its objects , and i am don't really know how to achieve it , since all objects i refer it , form. as declared in my forms.py so my question is someone could help me with given view and form how to, in HTML should i iterate my ForignKey objects
Please advice
Thanks
my code is shown below
my views.py Update view
class TaskIdUpdateView(UpdateView):
taskidformset = inlineformset_factory(MainTask,ChildTask, fields=('task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'))
model = MainTask
template_name = "taskid_update.html"
form_class = TaskUpdateForm
forms.py class form
class TaskUpdateForm(ModelForm):
TASK_STATUS_CHOICES = [
('ST', 'STARTED'),
('NS', 'NOT STARTED'),
('IP', 'IN PROGRESS'),
('PA', 'PAUSED'),
('CO', 'COMPLETED'),
]
INPUTֹTIMEֹFORMATS = ['%Y-%m-%d', # '2006-10-25'
'%m/%d/%Y',
'%Y/%m/%d', # '10/25/2006'
'%Y/%m/%d %H:%M',
'%m/%d/%y',
'%Y-%m-%d %H:%M:%S'] # '10/25/06'
#Main Task objects
task_title = forms.CharField(required=False, widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Task Title'}))
global_task_info = forms.CharField(required=True, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Task Description'}))
due_date = forms.DateTimeField(required=False, input_formats=INPUTֹTIMEֹFORMATS, widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
global_task_assign = forms.ModelChoiceField(queryset= UserProfile.objects.all(), widget=forms.Select(attrs={'class':'form-control'} ))
task_status = forms.ChoiceField(label='', choices=TASK_STATUS_CHOICES, widget=forms.Select(attrs={'class':'form-control'}))
complete = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input', 'id':'switchcomplete'}))
overall_precent_complete = forms.IntegerField(widget=(forms.NumberInput(attrs={'type':'range', 'min':'0', 'max':'100', 'value':'50', 'class':'range-slider__range', 'id':'PreRange'})))
task_location = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))
#Child Tasks objects
task_description = forms.CharField(max_length=200, widget=forms.TextInput(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_info = forms.CharField(max_length=500, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_complete = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'type':'checkbox', 'class':'custom-control-input', 'id':'switchcomplete'}))
sub_task = forms.CharField(max_length=500, widget=forms.Textarea(attrs={'class':'form-control','placeholder':'Sub Task Description'}))
task_precent_complete = forms.IntegerField(widget=(forms.NumberInput(attrs={'type':'range', 'min':'1', 'max':'100', 'value':'50', 'class':'slider', 'id':'myRange'})))
task_due_date = forms.DateTimeField(input_formats=INPUTֹTIMEֹFORMATS, widget=forms.DateTimeInput(attrs={
'class': 'form-control',
'id': 'picker'
}))
task_assign = forms.ModelChoiceField(queryset= UserProfile.objects.all(), widget=forms.Select(attrs={'class':'form-control'} ))
class Meta:
model = MainTask
fields = ['task_title',
'global_task_info',
'due_date',
'global_task_assign',
'task_status',
'complete',
'overall_precent_complete',
'task_location',
'global_task_assign',
'task_status',]
taskidformset = inlineformset_factory(MainTask,ChildTask, fields=('task_description','task_info','task_complete',
'sub_task','task_precent_complete','task_due_date','task_assign'))
update.html
{% extends 'base.html'%}
{% load static from static %}
{% block content %}
<!--accordion css-->
<link href="{% static 'css/range.css' %}" rel="stylesheet">
<div class="conatainer">
<div class="col text-center py-5">
<form action="" class="" method="POST">
<h3 class="mt-3 text-left">Update Task </h3>
<hr>
<p class="text-muted text-left">Update Itom task</p>
{% csrf_token %}
{% if form.errors %}
</form>
<!-- Error messaging -->
<div id="errors">
<div class="inner">
<p>There were some errors in the information you entered. Please correct the following:</p>
<ul>
{% for field in form %}
{% if field.errors %}<li>{{ field.label }}: {{ field.errors|striptags }}</li>{% endif %}
{% endfor %}
</ul>
</div>
</div>
<!-- /Error messaging -->
{% endif %}
<div class="input-group mt-3 mb-3 mr-auto">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1"><i class="fas fa-book-medical"></i></span>
</div>
{{ form.task_title}}
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-pen"></i></span>
</div>
{{form.global_task_info}}
</div>
<!---date time picker-->
<h6 class="text-left">Task Due Date</h6>
<div class="input-group date mb-3 col-3">
<div class="input-group-append">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
{{ form.due_date }}
</div>
<!--end of date time picker-->
<!---Task Location-->
<div class="input-group mb-3 mt-3 col-8">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-map-marked-alt"></i></div>
{{form.task_location}}
</div>
</div>
<!--End Of Task Location-->
<!---user assign-->
<h6 class="text-left">Assign Task to IT member</h6>
<div class="input-group mb-3 mt-3 col-8">
<div class="input-group-prepend">
<div class="input-group-text"><i class="fas fa-user-tie"></i></div>
{{form.global_task_assign}}
</div>
</div>
<!--End Of User Assign-->
<h6 class="text-left">Set Task Status</h6>
<div class="input-group mb-3 mt-3 col-4">
<div class="input-group-prepend">
<div class="input-group-text"><i class="far fa-caret-square-right"></i></div>
</div>
{{form.task_status}}
</div>
<div class="range-slider mb-4">
<h6 class="text-left">Set Task Global Progress</h6>
{{form.overall_precent_complete}}
<span class="range-slider__value">0</span>
</div>
<h4 class="mt-3 text-left">SubTask Section </h4>
<hr>
<!---subtask section-->
<div id="accordion">
{{formset.task_description }}
<div class="card">
<div class="card-header text-left bg-secondary">
<a class="card-link" data-toggle="collapse" href="#collapseOne">
Collapsible Group Item #1
</a>
</div>
<div id="collapseOne" class="collapse show" data-parent="#accordion">
<div class="card-body">
</div>
</div>
</div>
</div>
<!---End subtask section-->
<div class="col text-left">
<button type="submit" value="Save" class="btn btn-primary btn-lg text-white mt-2"><span><i class="fas fa-database"></i></span> Create Task</button>
</div>
</div>
</div>
{% endblock content %}
I have a html page that runs a for loop to populate students on a board. Here is screenshot and the code.
Issue: The issue is if i have more than one student in the class , no matter which button on the page i click it will not let me do a POST. If there is just a single kid in the class, the POST will work. So the post is failing and i don't know why. Thanks for the help in advance.
{% extends 'base.html' %}
{% load crispy_forms_tags %}
{% crispy K8Points_ClassroomForm %}
{% load static %}
{% block content %}
<br>
<h2>{% load static %}
<img src="{% static 'forms/star.png' %}" alt="chain" height="62" width="62"> My Classroom</h2>
<br>
<br>
<form action="/points/k8_points_classroom" method="POST">
{% csrf_token %}
<!-- Start Date -->
<div class="container">
<div class="container">
<div class='row'>
<div class="col-4">
<p> Recording Data as User : {{user.username}} </p>
<p><b> Classroom : {{class_name}} </b></p>
</div>
</div>
<div class='row'>
<div class = "col-2">
{{form.date|as_crispy_field }}
</div>
<div class = "col-2">
{{form.week_of|as_crispy_field }}
</div>
<div class = "col-2">
{{form.day|as_crispy_field }}
</div>
</div>
</div>
<div class="jumbotron" align="middle">
<h1>My Students</h1>
<!-- Line Break -->
<hr style="border: 1px solid black;"/>
<!-- Line Break -->
<div class="row mb-3">
{% for i in students %}
<div class="col-md-4 themed-grid-col"><h2>{{i.student_name}}</h2>
<p align="left"> Today's Score: </p>
<h4>
<button type="button" class="btn btn-primary btn-lg btn-block" data-toggle="modal"
data-target="#PointsBox1">Level Up
</button>
</h4>
<div id="PointsBox1" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<img src="{% static 'forms/star.png' %}" align="left" alt="chain" height="42"
width="42">
<h4 class="modal-title">Points Confirmation </h4>
<button type="button" class="close" data-dismiss="modal"> ×</button>
</div>
<div class="modal-body">
<h6>
<div class="modal-body">Please add the selected points for the current
student.</div>
</h6>
<div class="form-row" align='left'>
<div class="col-7">
{{form.class_name|as_crispy_field }}
{{form.student_name|as_crispy_field }}
{{form.time_frame|as_crispy_field }}
</div>
</div>
<div class="form-row">
<div class="col-3" align='left'>
{{form.behavior|as_crispy_field }}
{{form.academic|as_crispy_field }}
<button type="submit" class="btn btn-success"><i
class="fas fa-star"></i> Level Up
</button>
</div>
</div>
</div>
<div class="modal-foot"></div>
</div>
</div>
</div>
</div>
</form>
{% endfor %}
{% endblock %}
It's hard to know exactly what's going on because although you mention that "i click it will not let me do a POST" you don't mention exactly what error it jumps, or if it simply doesn't jump an error but doesn't save the information in the database.
However, I would start with two things:
There are errors in the html you designed. For example you open the form tag at the beginning of the code, but then you run a {% for i in students %} and inside that for you use </form> , which means that when you have several students, your code is going to have only one <form> tag but multiple </form> tags (I think that may be generating the error).
Try looking at the request.POST to see what the difference is when there is only one user with respect to when there are several. In the view that saves in the database the information, use print(request.POST), that can help you in the debugging.