Bootstrap Grid Doesn't work as expected - django

I want my main content and Sidewidget in the same row. With my knowledge of bootstrap grid, I tried to make this work but the sidewidget is stacking below the content and not in the sides. Here is the required snippets.
body.html
<!-- Navigation -->
{% include 'nav.html' %}
<!-- Page Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 ">
{% block content %}
{% endblock %}
</div>
<div class="col-lg-4">
{% block sidewidget %}
{% endblock %}
</div>
</div>
</div>
<!-- Bootstrap core JavaScript -->
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'js/tinymce/tinymce.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/tinymce/custom.js' %}" ></script>
nav.html
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'add' %}">Add Article</a>
</li>
{% endif %}
</ul>
</div>
</div>
My {% block content %}
{% for post in posts %}
<h2 class="mt-4">{{post.title}}</h2>
<!-- Author -->
<p class="lead">
by
{{post.author}}
</p>
<hr>
<!-- Date/Time -->
<p class="lead">Published on <b>{{post.published_date}}</b></p>
<hr>
<!-- Preview Image -->
<img class="img-fluid" src="{{post.image.url}}" alt="Img Placeholder">
<p>{{post.images}}</p>
{% for tag in post.tags.all %}
<p>{{tag.name}}</p>
{% endfor %}
<hr>
<!-- Post Content -->
<p class="lead">{{post.content|safe|truncatewords:"60"|linebreaks}}</p>
<footer class="entry-footer">
<button class="btn btn-primary">Read More</button>
</footer>
<hr>
{% empty %}
<h1> Nothing to display</h1>
{% endfor %}
{% endblock %}
My {% Sidewidget %} block
<!-- Search Widget -->
<div class="card my-4">
<h5 class="card-header">Search</h5>
<div class="card-body">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-secondary" type="button">Go!</button>
</span>
</div>
</div>
</div>
<!-- Categories Widget -->
<div class="card my-4">
<h5 class="card-header">Categories</h5>
<div class="card-body">
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
Web Design
</li>
<li>
HTML
</li>
<li>
Freebies
</li>
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled mb-0">
<li>
JavaScript
</li>
<li>
CSS
</li>
<li>
Tutorials
</li>
</ul>
</div>
</div>
</div>
</div>
<!-- Side Widget -->
<div class="card my-4">
<h5 class="card-header">Side Widget</h5>
<div class="card-body">
You can put anything you want inside of these side widgets. They are easy to use, and feature the new Bootstrap 4 card containers!
</div>
</div>
{% endblock %}
I have tried tweaking but nothing seems to work
I want the page like this:
|*****************************|
|navigationbar |
|*****************************|
|Post1(Col1-Col8) |SIDEWIDGET|
|***** | |
|Post2(Col1-Col8) | |
|***** | |
|PostN(Col1-Col8) | |
|*****************************|
|Footer |

Your code should work. The col-lg-* modifier applies only for screens that are over 1200px wide as per bootstrap's documentation. Maybe you're using a smaller screen and you also need to add the col-sm and col-md modifiers. Please try those and let me know if it works.
<div class="container">
<div class="row">
<div class="col-sm-8 col-lg-8 ">
{% block content %}
{% endblock %}
</div>
<div class="col-sm-4 col-lg-4">
{% block sidewidget %}
{% endblock %}
</div>
</div>
</div>

you can't use a bootstarp grid system for it because the sidewidget is going to take up the column of the whole three rows .You would have to use flex box for it. by using grid system columns can be individually used in different rows but you cannot have a whole column spanning over the different rows .

In the 'nav' section the 'nav' tag is not closed </nav>. close it and try again.
I think that will solve your problem.
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Start Bootstrap</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'add' %}">Add Article</a>
</li>
{% endif %}
</ul>
</div>
</div>
</nav>

Related

Bug Display whith chrome

I am currently on a python / Django project, I am also using bootstrap.
I have a display bug only with google chrome. When I load my page everything is fine then when I scroll, the bug occurs:
When I reload the page everything is back to normal:
This bug is not present on the project locally, only from production on a server (ubuntu with Gunicorn and Nginx). When I hover the mouse over this white block, the text displays randomly. This is not the only place where it happens. I don't know if this problem is known but I have absolutely no idea what it might be.
here is the part of the code that we see in picture :
<!-- Description content -->
<div class="container-fluid main-color-dark-bg pb-4">
<div lass="row">
<div class="col-lg-8 col-md-10 col-12 mx-auto mb-3">
< Précèdent
Suivant >
</div>
</div>
<!-- Description -->
<div class="row col-lg-8 col-md-10 col-12 mx-auto">
<div class="">
<p class="theoretical-watch-p ext-md-left text-center">
{{ video.description }}
</p>
</div>
</div>
<!-- Sous parties et Ressources -->
<div class="row mx-auto col-lg-8 col-md-10 col-12">
<!-- Sous parties-->
<div class="col-lg-7 col-12 px-0">
<h4 class="theoretical-subpart-title main-color-white text-md-left text-center ">Sous parties</h4>
<ul class="list-unstyled text-md-left text-center">
{% for s in subparts %}
<li class="">
<a href="{{s.subpart_url}}" class="subpart-link">
{{s.subpart_title |title}}
<span class="subpart-hook">[<span>
{% if s.subpart_time.hour == 0 %}
{{ s.subpart_time|time:"i:s" }}
{% else %}
{{ s.subpart_time|time:"H:i:s" }}
{% endif %}
<span class="subpart-hook">]<span>
</a>
</li>
{% endfor %}
</ul>
</div>
<!-- Ressources -->
<div class="col-lg-5 col-12 my-md-0 my-4 text-center mx-auto">
TÉLÉCHARGER LES RESSOURCES
</div>
</div>
</div>
<!-- End Description content -->
</div>
<!-- TAB Menu header mr-lg-auto mx-md-auto mx-sm-auto mx-auto -->
<div class="row col-12 px-0 mx-auto">
<ul class="nav mx-auto d-flex d-inline-flex" id="myTab" role="tablist">
<li class="d-inline-flex">
<a class="nav-link theoretical-tab-link active" id="tab-memo" data-toggle="tab" href="#content-memo" role="tab" aria-controls="content-memo" aria-selected="true">
Les points clés du chapitre
</a>
</li>
<li id="header-tab-program" class="d-inline-flex">
<a class="nav-link theoretical-tab-link" id="tab-program" data-toggle="tab" href="#content-program" role="tab" aria-controls="content-program" aria-selected="false">
Contenu du cours
</a>
</li>
<li class="d-inline-flex">
<a class="nav-link theoretical-tab-link" id="tab-definitions" data-toggle="tab" href="#content-definitions" role="tab" aria-controls="content-definitions" aria-selected="false">
Lexique
</a>
</li>
</ul>
</div>
<!-- TAB Menu content -->
<div class="">
<div class="tab-content w-100" id="myTabContent">
<!-- MEMO -->
<div class="tab-pane fade active show" id="content-memo" role="tabpanel" aria-labelledby="tab-memo">
<!-- Title vidéo et description -->
<div class="col-lg-8 col-12 mx-auto mb-5">
<!-- Title -->
<div class="row px-0 section-title my-auto col-12 mx-auto">
<div class="col-12 mx-auto my-auto">
<h1 class="mx-auto section-title text-center">
<hr class="main-color-grey-bg">
<img class="img-left" width="2%" height="auto" src="{% static 'images/pictograms/clover-black.svg' %}">
MÉMO
<img class="img-right" width="2%" height="auto" src="{% static 'images/pictograms/heart-red.svg' %}">
<hr class="main-color-grey-bg">
</h1>
</div>
</div>
<!-- APERCU - SECTION LEXIQUE -->
<div class="row mx-0">
<!-- colonne contenu -->
<div class="col-12">
<ul class="list-unstyled mt-5">
{% for sp in subparts %}
{% if sp.subpart_memo%}
<li class="theoretical-tab-content-p-memo">
<h4 class="">{{ sp.subpart_title |title }}</h4>
<p class="theoretical-tab-content-p-memo">
{{ sp.subpart_memo | safe | linebreaks}}
</p>
</li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
<!-- END MEMO -->
I don't use anything in particular in the code. I hope that someone could help me!
After multiple tests I finally identified the problem and solved.
The display bugs (as a reminder, only on google chrome), as seen in the videos and images came from a line that I had placed in my css file.
in my body I had the line overflow: overlay;
body{
font-family: 'main-font-medium', Fallback, serif;
font-weight: 0;
font-style: normal;
/*overflow: auto;*/
overflow-x: hidden!important;
scroll-behavior: smooth;
}
thanks to you JuhonRutila !
I hope this can help other people.

How to use Bootstrap tabs with Block Content in Django

I cannot figure out how to use Boostrap Tabs, when block content is needed and I am unable to make sue of the href in tab li a item. See below for any ideas. thanks for any help.
When you click on the below, it changes the tabs as expected, however, how do you incorporate django views? for example when the email tab is clicked, show the tab view for {% url 'account_email' %} in the content pane?
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-lg-7">
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-email-tab" data-toggle="tab" href="#nav-email" role="tab" aria-controls="nav-email" aria-selected="true">E-mail</a>
<a class="nav-item nav-link" id="nav-password-tab" data-toggle="tab" href="#nav-password" role="tab" aria-controls="nav-password" aria-selected="false">Password</a>
<a class="nav-item nav-link" id="nav-connect-tab" data-toggle="tab" href="#nav-connect" role="tab" aria-controls="nav-connect" aria-selected="false">Connect</a>
</div>
</nav>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="container mt-5 text-center mx-auto">
<div class="card p-5">
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-email" role="tabpanel" aria-labelledby="nav-email-tab">
{% block email_content %}{% endblock %}
</div>
<div class="tab-pane fade" id="nav-password" role="tabpanel" aria-labelledby="nav-password-tab">
{% block password_content %}{% endblock %}
</div>
<div class="tab-pane fade" id="nav-connect" role="tabpanel" aria-labelledby="nav-connect-tab">
{% block connect_content %}{% endblock %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
For this case, you have 2 options:
Load the whole page of {% url 'account_email' %} into a iframe, and display that iframe in the mentioned tab
put the template of {% url 'account_email' %} into an independent HTML file that can be included into the html section of this tab, using {% include "path to the html file" %}, and of course this HTMl template will use the same context as the current view, meaning you will have to send all the context data from the view of {% url 'account_email' %} into this view.
Remember that Django template render everything FROM THE SERVER SIDE, so everything end-user sees are pre-rendered before. Unless you use Ajax here.
I ended up completing the solution with a much more simple approach using request.path to set the appropriate tag active, then just use the tab href to directly reference the view for that tab.
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-lg-7">
<nav>
<div class="nav nav-tabs" id="nav-tab">
<a class="nav-item nav-link {% if 'accounts/email' in request.path %}active{% endif %}" id="nav-email-tab" href="{% url 'account_email' %}" aria-selected="true">E-mail</a>
<a class="nav-item nav-link {% if 'accounts/password/change' in request.path %}active{% endif %}" id="nav-password-tab" href="{% url 'account_change_password' %}" aria-selected="false">Password</a>
<a class="nav-item nav-link {% if 'accounts/social/connections' in request.path %}active{% endif %}" id="nav-connect-tab" href="{% url 'socialaccount_connections' %}" aria-selected="false">Connect</a>
</div>
</nav>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="container mt-5 text-center mx-auto">
<div class="card p-5">
{% block base_content %}
{% endblock %}
</div>
</div>
</div>
</div>
</div>

how to run a function from a link within popup modal bootstrap

I have a django project that includes a popup modal. The modal has tabs as links. When the user clicks on one of the tabs, it must perform a function and retrieve data from the database.
The problem is that once the user clicked on the tab nothing happened, and the function isn't initialized.
urls.py
path("events/<int:id>/", getEvents, name = "getEvents"),
views.py
def getEvents(request,id):
q1 = cursor.execute('SELECT Person_.ID FROM Person_ WHERE Person_.ID = {0}'.format(id))
print('q1==>',q1)
qresult = q1.fetchone()
print("qresult==>",qresult)
print("query is not empty!")
eventQ = cursor.execute('SELECT Person_.ID, Person_.Full_Name, Events.ID, Events.Event_Title, Events.Event_Details, Links.document_id from Person_, Events, Links where ( Person_.ID = {0}) and (Person_.ID = Links.A_Person or Person_.ID = Links.B_Person) and (Events.ID = Links.A_Event or Events.ID = Links.B_Event) ORDER BY Events.ID DESC '.format(id))
resultEvents = eventQ.fetchall()
return render(request,'pictureCard.html',{
"resultEvents":resultEvents,
"qresult":qresult,
})
pictureCrads.html
<!-- Popup Modal -->
{% for obj in object_list %}
<div id="popModel{{obj.0}}" class="modal fade modal-rtl" role="dialog">
<div class="modal-dialog modal-lg">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header Modal-Pic">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{ obj.1 }}</h4>
<img src="{% static '/img/card/1.png'%}"/>
</div>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact{{ obj.0 }}" role="tab" aria-controls="contact" aria-selected="false">contact us</a>
</li>
<li class="nav-item">
<a class="nav-link" id="event-tab" data-toggle="tab" href="{% url 'getEvents' obj.0 %}" role="tab" aria-controls="event" aria-selected="false">Events</a>
</li>
<li class="nav-item mr-auto btn-warning">
<a class="nav-link text-dark" id="contact-tab" data-toggle="tab" href="#picture" role="tab" aria-controls="contact" aria-selected="false">Picture</a>
</li>
</ul>
<div class="modal-body tab-content" id="myTabContent">
<div class="tab-pane fade" id="contact{{ obj.0 }}" role="tabpanel" aria-labelledby="contact-tab">{{ obj.9 }}</div>
{% for event in resultEvents %}
<div class="tab-pane fade" id="event{{ obj.0 }}" role="tabpanel" aria-labelledby="event-tab">
<button class="btn btn-primary" > events</button>
{{ event.2 }}
</div>
{% endfor %}
<div class="tab-pane fade" id="picture" role="tabpanel" aria-labelledby="contact-tab">
<a class="" href="#"><img class="" src="{% static '/img/card/1.png'%}"/></a>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
......
<footer class="card-footer card-footer-buttom text-center bg-info">
<form method="GET" action="{% url 'getEvents' obj.0 %}">
detais
</form>
</footer>
Probably django does not know {% for obj in object_list %}. Because you are sending 2 variables which are resultEvents and qresult, but your html file is looking for 'object_list' dictionary or list. This might be the problem.
Hope this helps,

Bootstrap, nav-stacked not actually stacking list entries

It seems I'm missing something obvious here
I expected the home blog contact entries to be stacked on top of one another at all times.
What am I missing?
This is what's actually rendering:
<body class="body" style="background-color:#f6f6f6">
<div class="container-fluid" style="min-height:95%; ">
<hr>
<div class="row">
<div class="col-sm-2">
<br>
<br>
<!-- Great, til you resize. -->
<!--<div class="well bs-sidebar affix" id="sidebar" style="background-color:#fff">-->
<div class="well bs-sidebar" id="sidebar" style="background-color:#fff">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" class="active"><a href='/'>Home</a></li>
<li role="presentation"><a href='/blog/'>Blog</a></li>
<li role="presentation"><a href='/contact/'>Contact</a></li>
</ul>
</div> <!--well bs-sidebar affix-->
</div> <!--col-sm-2-->
<div class="col-sm-10">
<div class='container-fluid'>
<br><br>
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
<footer>
<div class="container-fluid" style='margin-left:15px'>
<p>Contact | LinkedIn | Twitter | Google+</p>
</div>
</footer>
</body>
There's no well class in Bootstrap 4. The card class can be used instead.
Here's a code snippet that does pretty much what you'd expect:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container-fluid" style="min-height:90vh; ">
<hr>
<div class="row">
<div class="col-sm-3 col-md-2">
<br>
<br>
<!-- There's no "well" class in Bootstrap 4. The "card" class can be used instead. -->
<div class="card bs-sidebar" id="sidebar" style="background-color:#fff">
<nav class="nav nav-pills flex-column flex-sm-row2">
<a class="flex-sm-fill text-sm-center nav-link active" href="#">Home</a>
<a class="flex-sm-fill text-sm-center nav-link" href="#">Blog</a>
<a class="flex-sm-fill text-sm-center nav-link" href="#">Contact</a>
</nav>
</div> <!--bs-sidebar-->
</div> <!--col-sm-3 col-md-2-->
<div class="col-sm-9 col-md-10 ">
<div class='container-fluid'>
<div class="row">
<div class="col">
<br><br>
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row">
<div class="col">
<p>Contact | LinkedIn | Twitter | Google+</p>
</div>
</div>
</div>
</footer>
Reference:
https://getbootstrap.com/docs/4.0/migration/#panels-thumbnails-and-wells
https://getbootstrap.com/docs/4.0/components/navs/#working-with-flex-utilities

Django multiple active item carousel

I am pulling the products from database and trying to display them in multiple frames/items of carousel on a screen rather than a single item using for loop.
This is what my carousel looks like at present, as you will notice only one item is displayed, but i want it to display 4 items at one slide and next four on clicking arrow button and so on.
click here to see my carousel image.
my Django code looks like this--
<div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
{% for prod in pro %}
<div class="item{% if forloop.first %} active{% endif %}">
<div class="col-sm-3">
<div class="product-image-wrapper1">
<div class="single-products">
<div class="productinfo text-center">
<!--sample image, same for all--><img src="{% static 'header/images/home/2508__14291.1437672247.200.200.jpg' %}" alt="" />
<h2>{{prod.productname}}</h2>
<p>{{prod.producttype}}</p>
<i class="fa fa-shopping-cart"></i>Add to cart
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>
</div>
Try to do something like this:
<div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
{% for prod in pro %}
<div class="col-sm-3">
<div class="product-image-wrapper1">
<div class="single-products">
<div class="productinfo text-center">
<!--sample image, same for all--><img src="{% static 'header/images/home/2508__14291.1437672247.200.200.jpg' %}" alt="" />
<h2>{{prod.productname}}</h2>
<p>{{prod.producttype}}</p>
<i class="fa fa-shopping-cart"></i>Add to cart
</div>
</div>
</div>
</div>
{% if forloop.counter|divisibleby:4 and not forloop.last %}
</div>
<div class="item">
{% endif %}
{% endfor %}
</div>
</div>
<a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>