I'm using django for templates. Here is the base:
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<main role="main" class="container">
<div class="pb-2 mb-2">
{% block page_header %}{% endblock page_header %}
</div>
<div class="mt-1 border-top">
{% block content %}{% endblock content %}
</div>
</main>
When the page_header div is given the class border-bottom, the border appears at the bottom of the contents instead of the page_header, not separating the two divs at all. When the content div is given the class attribute border-top, the contents are clearly separated from the page_header by a line. Why doesn't this occur with border-bottom?
page_header, plugged into the {% block page_header %}
<h2 class="d-inline">Topic: Private</h2>
<p class="ml-3 d-inline">Entries:</p>
<p class="alert-gray rounded p-1 pl-2 pr-2 d-inline border-0">2/3</p>
<a class="btn btn-gray p-2 ml-5 d-inline" href="/edit_topic/13/">
<i class="fas fa-edit"></i>
Edit topic name
</a>
<form class="ml-5 d-inline" action="/delete_topic/13/" method='post' title="Delete Topic">
<input type="hidden" name="csrfmiddlewaretoken" value="">
<button class="btn btn-red p-2" name="submit">
<i class="fas fa-minus-circle"></i>
Delete topic
</button>
</form>
<div class="btn-group dropright ml-5 d-inline" title="Visibility">
<button type="button" class="btn btn-primary btn-md rounded-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="far fa-eye-slash"></i>
</button>
<div class="dropdown-menu w-10">
<form class="dropdown-item" action="/topic_visibility/13/0" method='post' title="Private">
<input type="hidden" name="csrfmiddlewaretoken" value="">
<button class="dropdown-button" name="submit">
<i class="far fa-eye-slash"></i>
</button>
</form>
<form class="dropdown-item" action="/topic_visibility/13/1" method='post' title="Public">
<input type="hidden" name="csrfmiddlewaretoken" value="">
<button class="dropdown-button" name="submit">
<i class="far fa-eye"></i>
</button>
</form>
</div>
It was due to an un-closed div tag.
Related
When collapsing the window before it hits the medium breakpoint, the column containing the select field overlaps the first column with the "heading". Not sure why. Any help would be appreciated.
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<div class="row">
<div class="col-md-1">
<span class="h2">Leads</span>
</div>
<div class="col-md-3">
<form>
<input type="hidden" name="status" id="status" value="Today">
<input type="hidden" name="tab" id="tab-status-agent" value="follow_up">
<select name="user_id" id="select-agent" class="form-control" onchange="this.form.submit()">
<option value="">All Team Members</option>
<option value="unassigned">Unassigned</option>
<option value="7">Luke Skywalker</option>
<option value="2">Han Solo</option>
<option value="1">Leia Organa</option>
</select>
</form>
</div>
<div class="col-md-5 text-right">
<form data-remote="false" class="d-inline" id="power-dialer-form" action="/calls/power_dialer" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="vqtLpEeM2kh5MP7nZFhFrfrmJhjm6T3IF++8UGmHpHjZP4E9WSOpIsextGJptcRYPIuDBqVWgDkVYeHOn9uWow==">
<button type="submit" name="commit" value="" class="btn btn-primary" id="add-to-power-dialer" disabled="">
<i class="fas fa-phone" title="Add to power dialer"></i>
</button>
</form>
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-primary" data-toggle="modal" data-target="#assign-leads" title="Assign leads" href="#">
<span class="fas fa-user-check"></span>
</a> <a class="btn btn-primary" data-toggle="modal" data-target="#new-lead" title="New lead" href="#">
<span class="fas fa-user-plus"></span>
</a> <a class="btn btn-primary" data-toggle="modal" data-target="#import-leads" title="Import leads" href="#">
<span class="fas fa-file-import"></span>
</a>
</div>
</div>
<div class="col-md-3">
<div class="input-group search-bar">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon"><i class="fas fa-search"></i></div>
</div>
<input type="search" id="search" class="form-control">
</div>
</div>
</div>
I attempted this setting:
ROW: COL-2 COL-3 COL-4 COL-3
Which fixes the overlap but then the select field is too far away from the heading.
Please try this code i hope it will be worked
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.6.0/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<div class="row">
<div class="col-md-4">
<span class="h2">Leads</span>
<form class="ml-3">
<input type="hidden" name="status" id="status" value="Today">
<input type="hidden" name="tab" id="tab-status-agent" value="follow_up">
<select name="user_id" id="select-agent" class="form-control"
onchange="this.form.submit()">
<option value="">All Team Members</option>
<option value="unassigned">Unassigned</option>
<option value="7">Luke Skywalker</option>
<option value="2">Han Solo</option>
<option value="1">Leia Organa</option>
</select>
</form>
</div>
<div class="col-md-5 text-right">
<form data-remote="false" class="d-inline" id="power-dialer-form" action="/calls/power_dialer" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="vqtLpEeM2kh5MP7nZFhFrfrmJhjm6T3IF++8UGmHpHjZP4E9WSOpIsextGJptcRYPIuDBqVWgDkVYeHOn9uWow==">
<button type="submit" name="commit" value="" class="btn btn-primary" id="add-to-power-dialer" disabled="">
<i class="fas fa-phone" title="Add to power dialer"></i>
</button>
</form>
<div class="btn-group" role="group" aria-label="Basic example">
<a class="btn btn-primary" data-toggle="modal" data-target="#assign-leads" title="Assign leads" href="#">
<span class="fas fa-user-check"></span>
</a> <a class="btn btn-primary" data-toggle="modal" data-target="#new-lead" title="New lead" href="#">
<span class="fas fa-user-plus"></span>
</a> <a class="btn btn-primary" data-toggle="modal" data-target="#import-leads" title="Import leads" href="#">
<span class="fas fa-file-import"></span>
</a>
</div>
</div>
<div class="col-md-3">
<div class="input-group search-bar">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon"><i class="fas fa-search"></i></div>
</div>
<input type="search" id="search" class="form-control">
</div>
</div>
</div>
HTML file:
<div class="container h-100">
<div class="row h-100">
<div class="col">
<h1>{{ auction.name }}</h1>
</div>
<div class="col">
<form method="POST" action="{% url 'bid' auction.id %}">
{% csrf_token %}
<input name="bid" type="number" required><br>
<input type="submit" value="Make a bid!">
</form>
<a class="btn btn-warning" href="{% url 'close' %}">Close auction</a>
</div>
</div>
</div>
I would like to put the <a class="btn btn-warning" href="{% url 'close' %}">Close auction</a> in the bottom of the <div class="col"> and in the center horizontally, how can I do? Thank you!
This is most simply accomplished using a flexbox layout. The following is not tested but according to the bootstrap docs should give you what you want.
<div class="col d-flex flex-column justify-content-between align-items-center">
<form method="POST" action="{% url 'bid' auction.id %}">
{% csrf_token %}
<input name="bid" type="number" required><br>
<input type="submit" value="Make a bid!">
</form>
<a class="btn btn-warning" href="{% url 'close' %}">Close auction</a>
</div>
In order to make your button in the bottom of your form you should add a new row (new div with the class row), and in order to center it horizontally you should add one of these classes: pagination-centered or text-center as suggested by this answer. The final code may be similar to this :
<div class="container h-100">
<div class="row h-100">
<div class="col">
<h1>{{ auction.name }}</h1>
</div>
<div class="col">
<form method="POST" action="{% url 'bid' auction.id %}">
{% csrf_token %}
<input name="bid" type="number" required><br>
<input type="submit" value="Make a bid!">
</form>
<div class="row pagination-centered">
<a class="btn btn-warning" href="{% url 'close' %}">Close auction</a>
</div>
</div>
</div>
</div>
Try this. This may take some editing to get it exactly how you like it, but it should put the warning button below the other buttons and in the center. The key here is the bootstrap class "offset-(number of columns)"
<div class="container h-100">
<div class="row h-100">
<div class="col">
<h1>{{ auction.name }}</h1>
</div>
</div>
<div class="row">
<form method="POST" action="{% url 'bid' auction.id %}">
<div class="col-3">
{% csrf_token %}
</div>
<div class="col-3">
<input name="bid" type="number" required><br>
</div>
</div>
<div class="offset-5">
<input type="submit" value="Make a bid!">
</div>
</form>
</div>
<div class="row">
<div class="offset-5 col-1">
<a class="btn btn-warning" href="{% url 'close' %}">Close auction</a>
</div>
</div>
</div>
I was following a tutorial online to try and create a delete modal from Bootstrap, but it is not picking up on the userid from my users table. The users table is stored on a sql database.
I keep getting the error: jinja2.exceptions.UndefinedError: 'list object' has no attribute 'id'
I have tried looking at similar questions on the stackoverflow site but I am unable to get this working, as I am still learning code and struggling with relating the answers to my setup.
Thanks in advance for anyone that can help.
So below is my delete function.
#app.route("/user/<int:user_id>/delete", methods=['POST'])
#login_required
def delete_user(user_id):
user = User.query.get_or_404(user_id)
db.session.delete(user)
db.session.commit()
flash('The account has been deleted', 'success')
return redirect(url_for('view_user'))
Then this is my html page.
{% extends "layout.html" %}
{% block content %}
<div class="container">
<div class="table-wrapper">
{% with messages = get_flashed_messages(with_categories=true)%}
{% if messages%}
{% for category, message in messages %}
<div class="alert alert-{{category}}">
{{ message}}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="table-title">
<div class="row">
<div class="col-sm-8">
<h2>User Account <b>Details</b></h2>
</div>
<div class="col-sm-4">
<div class="search-box">
<i class="fas fa-search"></i>
<input type="text" class="form-control" placeholder="Search…">
</div>
</div>
</div>
</div>
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>#</th>
<th>Username<i class="fa fa-sort"></i></th>
<th>Email Address<i class="fa fa-sort"></i></th>
<th>Role<i class="fa fa-sort"></i></th>
<th>Actions</th>
</tr>
</thead>
{% for user in user %}
<tbody>
<tr>
<td>{{user.id}}</td>
<td>{{user.username}}</td>
<td>{{user.email}}</td>
<td>{{user.role}}</td>
<td>
<a href="{{url_for('update_user', user_id=user.id)}}" class="edit" title="Edit"
data-toggle="tooltip"><i class="fas fa-edit"></i></a>
<button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button>
</td>
</tr>
</tbody>
{% endfor %}
</table>
<!-- Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">Delete User?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<form action="{{ url_for('delete_user', user_id=user.id) }}" method="POST">
<input class="btn btn-danger" type="submit" value="Delete">
</form>
</div>
</div>
</div>
</div>
<div class="clearfix">
<div class="hint-text">Showing <b>5</b> out of <b>25</b> entries</div>
<ul class="pagination">
<li class="page-item disabled"><i class="fa fa-angle-double-left"></i></li>
<li class="page-item">1</li>
<li class="page-item">2</li>
<li class="page-item active">3</li>
<li class="page-item">4</li>
<li class="page-item">5</li>
<li class="page-item"><i class="fa fa-angle-double-right"></i></li>
</ul>
</div>
</div>
{% endblock content %}
Just in case it is needed this is my user table
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), nullable=False, unique=True)
email = db.Column(db.String(80), nullable=False, unique=True)
password = db.Column(db.String(120), nullable=False)
role = db.Column(db.String(80))
<form action="{{ url_for('delete_user', user_id=user.id) }}" method="POST">
<input class="btn btn-danger" type="submit" value="Delete">
</form>
user is python list so you can't able to use here that is why you are getting this error, so inorder to delete specific user you should use one user's route then you can deal with that user.
or
<td>
<i class="fas fa-edit"></i>
<button type="button" class="btn btn-danger btn-sm m-1" data-toggle="modal" data-target="#deleteModal">Delete</button>
</td>
change to
<td class="btn btn-danger" onclick="return confirm('Are you to delete this user?')">Drop</td>
and remove the whole model.
This one will help you to have default model instread of Bootstrap model
Hope that will help you
so here's the problem
i want to align my buttons , in the div
here the result
my view
i've tried some css but it dont work
now i am not using any custom css for this div
here's my blade file
<td>
<div class="container">
<form method="POST" action="{{ route('users.destroy',$user->id) }}">
{{ csrf_field() }}
{{ method_field('delete') }}
{{-- <!–– //With the <a> tag you are sending a get request.
that's why we changed it like that because the destroy method require a DELETE request
thank you stackoverflow you saved me ––> --}}
<button type="submit" class="btn btn-danger" ><i class="fa fa-trash-o" aria-hidden="true"></i>
</button>
</form>
<a href="{{ route('users.show',$user->id) }}"><button type="button" class="btn btn-primary"><i class="fa fa-info-circle" aria-hidden="true"></i></button>
<a href="{{ route('users.edit',$user->id) }}"> <button type="button" class="btn btn-warning"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>
</div>
</td>
Add text-nowrap class to the form, and they will be in one line.
I'm building a webpage using the extend templating feature of django. I thus have a base.html where I have search fields that I want to display differently depending on the webpage that is extending base.html. Here are the fields that I want to show:
The corresponding code is:
<div class="row">
<div class="container-fluid col-md-offset-9 col-md-3">
<a href="../posts/newpost/" class="btn btn-info" role="button">
<span class="glyphicon glyphicon-education" aria-hidden="true"></span> Buton
</a>
</div>
</div>
<div class="container-fluid">
<h1 id="Titre" align="center">Title </h1><br>
</div>
<div class="col-md-12" style="height:100px;"></div>
<form class="form-inline text-center" action="{% url 'posts:postsearch' %}" id="form-searchLessons">
<div class="form-group">
<input type="text" class="form-control input-lg" id="typeCours" list="matieres" placeholder="Keyword" name="discipline" autocomplete="off">
</div>
<div class="form-group">
<input type="text" class="form-control input-lg" id="Localisation" placeholder="Lieu."
name="localisation" onFocus="geolocate()">
</div>
<button type="submit" class="btn btn-default btn-lg" id="btn-getLessons">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Trouver !
</button>
</form>
</div>
In case of page1, I want the fields to appear like the image above.
Then if I extend base.html from page2, this should like this:
Which currently I write a complete different page:
<div class="container-fluid">
<div class="row reduced_search-bar">
<div class="col-lg-9">
<form class="form-inline">
<div class="form-group">
<input type="text" class="form-control" id="typeCours" placeholder="Keyword">
</div>
<div class="form-group">
<input type="text" class="form-control" id="Localisation" placeholder="Lieu">
</div>
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span> Trouver !
</button>
</form>
</div>
<div class="col-lg-3">
<a href="{% url 'posts:add' %}" class="btn btn-info" role="button">
<span class="glyphicon glyphicon-education" aria-hidden="true"></span> Buton ?
</a>
</div>
</div>
</div>
What I want, is to have all this code in one single base.html. That I print differently depending whether I'm extending from page1, or page2.
If I understood it correctly, you can pass an extra context from your view which will determine which code to show:
# views.py
from django.shortcuts import render
def page1(request):
return render(request, 'page1.html')
def page2(request):
return render(request, 'page2.html', {'page2': True})
# base.html
{% if page2 %}
# Necessary code for page 2
{% else %}
# Necessary code for other pages
{% endif %}
# page1.html
{% extends 'base.html' %}
# page2.html
{% extends 'base.html' %}