I have my HTML file which links to the CSS and it is working fine
<link rel="stylesheet" href="{% static '/Website/css/bootstrap.min.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/style.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/ionicons.min.css' %}" />
<link rel="stylesheet" href="{% static '/Website/css/font-awesome.min.css' %}" />e here
Then I have several images in the HTML file which are loading fine
<link rel="shortcut icon" type="image/png" href="{% static '/Website/images/fav.png' %}"/>
One div element id <div id="lp-register"> obviously links to above style.css selector as per below
#lp-register{
background: linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0)), url('../images/test.png') fixed no-repeat;
background-size: cover;
background-position: center;
position: absolute;
top: 0;
width: 100%;
min-height: 100vh;
}
the images are in the static folder structured as this
static
- images
- test.png
and the setting.py has the correct static file definition
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
When I load the HTML page that particular image is not being loaded, and no error I see in the Django server, furthermore if I inspect the element I see that url('../images/test.png') remain with the old settings
linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0.7)), url("http://placehold.it/1920x1280") fixed no-repeat
and does not change no matter what. In addition to that if I inspect the element and modify the settings manually to
linear-gradient(to right, rgba(0,0,0, 0.7) , rgba(0,0,0, 0)), url('../images/test.png') fixed no-repeat
which is what I want, seems that is working fine but when I change it in CSS does not
Can anybody help please?
{% load static%} in your HTML and then load the stylesheet.
You have set the static files in the settings.py the correct way, I think this should work.
url('../images/test.png') for this kind of linking in CSS we have to use this way to call these static files
url('{% static 'images/test.png' %}')
Related
My folder layout is:
/env
app.py
/env/static/styles
main.css
/env/static/img
contains all the image
/env/templates
index.html
My main.css contains:
#background_section_top {
width: 100%;
height:88px;
background: url(static/img/background_section_top_bg.jpg);
background-repeat: repeat-x;
}
My index.html contains:
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='styles/main.css') }}">
But I couldn't see the image in my index.html. Could you please help where I'm doing mistake? Thanks.
Just modify
background: url(static/img/background_section_top_bg.jpg);
to
background: url(/static/img/background_section_top_bg.jpg);
I have a Django/Python application and I want to use semantic UI in my views. I'm importing semantic using the CDN link, so my base HTML file has the following header...
<head>
...
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui#2.4.2/dist/semantic.min.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght#300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="{% static "styles.css" %}">
...
</head
As you may see I want to load google fonts. However, all semantic UI elements seem to use the Lato, 'Helvetica Neue', Arial, Helvetica, sans-serif font by default and this is difficult to override.
All the advice I've seen online tells me to "customize the site.variables file". But where is this site.variables file? Is it something that I make, and if so, where do I put it so Semantic UI can detect it?
UPDATE: This is my CSS
html {
font-family: 'Montserrat', sans-serif;
}
Error here.
href="{% static "styles.css" %}"
Should be href="{% static 'AppName/styles.css' %}".
You can't you double quotes inside double quotes.
You may also like to use django-semantic-ui
I am trying to style a website using a stylesheet.css file.
In one of my html pages, I have the <link rel="stylesheet" href="stylesheet.css"> element. The css file is in my templates folder (image):
When I start the application and go to a page, The console reads:
"GET /home/stylesheet.css HTML 1.1/" 200
But the page doesn't appear to load correctly (meaning none of the CSS settings are applied). I am using repl.it to run this website.
Here is the link to the repl: sm--supermechm500.repl.it [REPL.IT]
Here is my css file:
#import url('https://fonts.googleapis.com/css?family=Aldrich&display=swap');
body {
align-items: center;
text-align: center;
background-color: #000000;
width: auto;
height: auto;
font-family: 'Aldrich', sans-serif;
}
I have already reviewed this question: Application not picking up css file
, but I didn't quite understand the answer provided, or the question's code.
What is the proper way to make flask render a page using a stylesheet?
After some research, I found that I have done it all wrong.
I needed a "static" folder in my directory, in which is another folder named "css".
In that folder is the stylesheet.css
/ = folder
main.py
/templates
pages.html
/static
/css
stylesheet.css
other_files.txt
And within the html, replace<link rel="stylesheet" href="stylesheet.css">
with<link rel="stylesheet" href="{{ url_for('static', filename='css/stylesheet.css') }}">
And just a note, just because the console says status code "200" FOUND doesn't mean it was loaded, or loaded correctly.
To be more specific, actual solution is
To create a "css" folder in "static" folder.
Add css in path of ".css" file
Change => href="{{ url_for('static', filename='stylesheet.css') }}" to href="{{ url_for('static', filename='css/stylesheet.css') }}"
OR
Change => href="../static/main.css" to href="../static/css/main.css"
When adding a prepared template such as bootstrap template into a django project. I change all src path which is linking local statics files such as javascript, css and images.I want to automate this operations .Is there any way for doing this ? In my opinion,using regex it will be possible.Howeever I can not until now
I put a few patterns down to be the example
<img src="images/slide-dark.jpg" alt="" >
<link href="css/animate.css" rel="stylesheet">
<script src="js/bootstrap.min.js"></script>
will be like this
<img src="{% static 'images/slide-dark.jpg' %}">
<link href="{% static 'css/animate.css' %}" rel="stylesheet">
<script src="{% static 'js/bootstrap.min.js' %}"></script>
I'm trying to load an image to my page and set it as my background, below is the css and html that I am working with. The CSS page seems to load, as my test font and background colors show up but for whatever reason my background image doesn't.
I am using Django as my web framework.
Appreciate the help!
HTML:
<!DOCTYPE html>
{% load staticfiles %}
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="{% static 'personal/css/frontpagebackground.css' %}" type = "text/css"/>
</head>
<body>
<p>This is a test</p>
</body>
</html>
CSS:
body
{
background-image:url(personal/static/personal/img/home.jpg) no-repeat;
background-repeat:no-repeat;
background-size:100%;
background-color: green;
min-height: 100%;
}
p {
font-style: italic;
color: red;
}
You used background-image, so the no-repeat is not actually working. Try adding the no-repeat below as background-repeat: no-repeat;.
background-image: url('image-url-here.png');
background-repeat: no-repeat;
I've had problems like this with django, primarily because my {% static %} location was confusing me. I think this is a non-css issue, and a path issue.
It helped me to use the dev console to check for Resource Failed To Load error. It will spit out the path that the machine is looking for, and it's likely different than what you specified.
I.e. is your css file located along
personal/static/personal/img/home.jpg
relative to your css file? You might just need to back up a directory, i.e.
../personal/static/personal/img/home.jpg
Either way, the console should give you your path, and use that to determine where your CSS file is digging for the image.
If your CSS files are in a path such as /static/css/style.css
and the images are under a path such as /static/images/test.jpg
then you have to place the test.jpg image directly in the folder with the style.css i.e. /static/css/test.jpg and in your HTML file give it the name test.jpg without using the static path i.e. background-image:url('test.jpg');:)