Actually I am creating a Basic E-Commerce Flask Application.
Data of the price, discount and everything is provided from content.json file to the function in python from where it goes to home.html file such that each product's data is represented in specific boxes.
It currently looks like this..
I just added random data here for reference...
Here I want all the boxes to be placed in a grid of 2 or 3 columns depending upon the width of the screen.
I have placed all the boxes generated from the jinja for loop in the boxes class.
<div class="boxes">
{% for item in data %}
<div class="card bg-dark text-white" style="width: 23rem;">
<div class="card-body">
<h5 class="card-title">{{item}}</h5>
<h6 class="card-subtitle mb-2 text-muted">Category: {{item.split(" ")[len(item.split(" "))-1]}}s</h6>
<p class="card-text" id="cut">Actual Price: {{data[item].price}} Rupees</p>
<p class="card-text">New Price: {{round(((100-data[item].discount)/100)*data[item].price)}} Rupees</p>
<p class="card-text">Discount: {{data[item].discount}}%</p>
<p class="card-text">Ratings: {{ data[item].rating }}⭐</p>
Buy Now
Product Details
</div>
</div>
</div>
but, when I applied grid properties and styles in 'boxes' class it seems to work only on the first box like the margin etc, and not in the other boxes.
Like this:
see here it's only applied to first box
I think it's because of the dynamic data generated due to jinja for loop that's causing this issue, and I don't know how to solve this.
the style for 'boxes' class:
.boxes {
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 10px;
padding: 10px;
}
So yeah the main problem is how to apply this grid to all the boxes present in the boxes class
Related
Need some help with my first python project (also my first post on stackoverflow). Appreciate your time and help!
I am trying to automate regular booking on a website using selenium and chrome webdriver. The booking page is a timetable, with each cell corresponding to a timeslot and "Book" buttons within each cell/timeslot.
However, the XPATH for these buttons turns out to be dynamic.
E.g. //*[#id="root"]/div[4]/div/div[4]/div/div[3]/div[69]/div[3]/button
Each cell and button for the different timeslots has the same html class name and type. So would it be possible to search for the text in each cell (e.g. Class 1.10 7:30) and click the corresponding button within the same cell?
<div class="column">
<div class="cell even">
<span class="d-block d-sm-none">Sat, 17th Jul</span>
<span class="d-none d-sm-block">Saturday, 17th July</span></div>
<div class="cell event " style="color: rgb(255, 255, 255); top: 8rem; height: 6rem;">
<div>Class 1.1</div>
<div>07:30</div>
<div class="position-relative">
<button class="btn btn-warning" type="button">Book</button>
</div>
</div>
<div class="cell event " style="color: rgb(255, 255, 255); top: 16rem; height: 6rem;">
<div>Class 1.2</div>
<div>08:30</div>
<div class="position-relative">
<button class="btn btn-warning" type="button">Book</button>
</div>
</div>
Yes, it is possible.
If you want to match 2 texts in 2 elements as shown in the HTML you presented and I guess the texts are passed to the method as parameters, it will be something like this:
btn_xpath = ("//div[./div[contains(text(),'Class $class')] and (./div[contains(text(),'$time')])]//button[text()='Book']",(class=class, time=time))
driver.find_element_by_xpath(btn_xpath).click()
Here class and time are parameters passed from outside to select the desired class and time.
In case the selection can be unique by the time only it will be like this:
btn_xpath = ("//div[./div[contains(text(),'$time')]]//button[text()='Book']",(time=time))
driver.find_element_by_xpath(btn_xpath).click()
I have a loop that fills the page with pictures but they do so vertically.
{% for i in range(amount) %}
<div class="col-xs-12 col-sm-6 col-md-3 col-lg-3">
<div class="contents-block">
<div class="image"><img src="/static/assets/img/uploaded/coro.png" />
</div>
</div>
</div>
{% endfor %}
</div>
How do i make it so that the pictures fill the entire page in a grid?
Your images are lining up in a column because all your <img> tags are under a parent column. And the reason why the right side part is empty and the single image is not covering the entire width is due to the size of the image.
To answer your question on how to make an image grid covering the entire width, my idea will be to contain all the images inside a div and use n columns
<div class="images">
{% for i in range(amount) %}
<img src="/static/assets/img/uploaded/coro.png" />
{% endfor %}
</div>
and the CSS will be
.images {
/* Prevent vertical gaps */
line-height: 0;
column-count: 5; /* this depends on size, no.of images and viewport(for making it responsive) */
column-gap: 0px;
}
.images img {
width: 100% !important;
height: auto !important;
padding: 3px;
}
I am trying to build a drop-down menu in a navbar. I have done this, but the list of items is too long to fit on the page (the bottom of the list is hidden) so I therefore need to make the list scrollable. As of now, when the menu is "open" and I scroll, it scrolls the page behind the menu rather than the menu. Please help me figure this out! Below I have posted a bit of my HTML and CSS as it pertains to this drop down menu.
<li class="nav-item dropdown">
INSTRUMENTS
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
{% for instrument in instruments %}
{{ instrument.name }}
{% endfor %}
</div>
</li>
.scrollable-menu {
height: auto;
max-height: 500px;
overflow-x: hidden;
}
Have you tried using overflow-y: auto or overflow-y: scroll yet? Don't have the time to work on an example at the moment, but that should point you in the right direction.
You can find a similar post here for more info.
I think you are missing the correct selector.dropdown-menu is the correct selector if not solved then try overflow:auto;
if not solved then try this example
I'm working on Bootstrap and I'm pretty new to front-end. I don't have a CSS file, all i have is a html file included in my python django project. In this file I', trying to put a background image from my section.
This image doesn't show up fully or expand to the full size. I'm not sure how to make it responsive background section with the image included and I'm not sure how to make sure this section atleast expands to full size or a size of page. Can you please help.
Whatever i try to find online shows as CSS, and i don't want to include css right now. Just want to keep it simple with boostrap html file. Here is the code below.
<section class="jumbotron text-center" style="background:transparent url({%static 'workspace.jpg'%}) no-repeat center center /cover">
<div class="container">`enter code here`
<h1 class="jumbotron-heading">Name heading</h1>
<p class="lead font-weight-bold text-muted">Test 2</p>
<p>
Email
</p>
</div>
</section>
To add a background image to a container with inline CSS you can do this:
Note*: Make sure to remove the border: 1px solid red;. This was just for demonstration.
<div class="container" style="border: 1px solid red; background-image: url('https://i0.wp.com/wptavern.com/wp-content/uploads/2016/07/stack-overflow.png?ssl=1'); background-size: 100% 100%; background-repeat: no-repeat;">
<p style="padding: 100px;">content</p>
</div>
you can add this code in the style tag like this <style>.jumbotron .text-center{background-size:cover; background-repeat:no-repeat; background-position:center;}</style>i would suggest you to add a specific call to your section the style will only effect the specific div only.
if you want add inline the do like this style="background-image:url(img);background-size:cover; background-repeat:no-repeat; background-position:center; "
My code:
<html>
<style type="text/css">
h1 {
position: absolute;
top: 5px;
left: 200px;
}
form #Edit1 {
position: absolute;
top: 37px;
left: 410px;
}
form #Edit2 {
position: absolute;
top: 37px;
left: 840px;
}
</style>
<font size="4" face="arial" color="#0000FF">
<h1>XML Search</h1>
</font>
<br/>
<br/>
<Form Action ="/search/" Method ="POST">
<div id="Edit1">
<INPUT TYPE = 'VARCHAR' name ='word' VALUE ="" size = "50">
</div>
<div id="Edit2">
<INPUT TYPE = "Submit" VALUE = "Search">
</div>
<br/>
<hr/>
{% csrf_token %}
</Form>
{% if list1 %}
<br/>
<head>
#!/usr/bin/python
# make a horizontal bar chart
from pylab import *
val = 3+10*rand(5) # the bar lengths
pos = arange(5)+.5 # the bar centers on the x axis
figure(1)
barh(pos,val, align='center')
{% for l in list1 %}
xticks(pos, ({{l.file_name}},))
{% endfor %}
xlabel('Performance')
title('How fast do you want to go today?')
grid(True)
show()
</head>
<body>
<div id="chart_div" style="width: 1000px; height: 500px;"></div>
</body>
{% endif %}
</html>
I have created an app in Django called 'search' which searches the keywords entered by the user in 10xml documents and maintain the frequency of their occurrence for each file. When user enters the words he gets the results as graphs. This above mentioned HTML code file is redirected from views.py file. On running the app on the server, the Python code employed alongwith the HTML code, gets printed as it is when user enters the keywords. How can I display the charts created in pylab in HTML page?
I have another idea, I used up Google charts earlier and they are working fine. The only problem with them is that they will not work if there is no Internet, and this will be a drawback in may app. Is there any way out to solve this, I mean how can we use Google charts statically? If anyone of you want you want me to upload my Google charts code, I can do that.
You need to use the FigureCanvasAgg backend and return a HttpResponse. See for instance:
[Django with Matplotlib][1]
How to use Matplotlib in Django?