I am very new to web design and I need help with a problem I have at the moment. I have written a web page with the help of Django that pulls values out of a MySQL database and places them on webpage using an embedded for loop. The values in the database are constantly updated and to get the new values displayed at the moment I am simply refreshing the page. This method seems very clunky and I was wondering if there was easy way to have them update without a refresh?
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="refresh" content="0.5">
<link rel="stylesheet" href="css/style.css">
<link href="images/favicon.ico" rel="shortcut icon">
<title>Health monitor</title>
</head>
<body>
<div class="container">
<h1>Health Monitor</h1>
<h2>Temperature Data</h2>
{% for heat in temp %}
<h3>Current temperature {{ heat.hot }} </h3>
<p>You might want to call a nurse</p>
{% endfor %}
There are a couple ways, perhaps the simplest and most accessible would be to use ajax polling to request updates on an interval.
This would be done in JavaScript. Every x seconds you would make a request to your django app to see if there are any changes.
Related
My understanding
So my understanding is, if you have a website with the following source:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HTML 5 Boilerplate</title>
<link rel="stylesheet" href="style.css">
<script src="script-head.js"></script>
</head>
<body>
<img width="400" src="image.jpg" />
<script src="script-closing.js"></script>
</body>
</html>
...the browser will queue the assets to be loaded in the following order (the order they appear in the page source):
style.css
script-head.js
image.jpg
script-closing.js
I have tested this simple HTML page in Chrome Dev Tools Network tab and the assets do load in that order.
All makes sense to me. So far so good.
The confusion
But in practice, I'm working on optimising the Largest Contentful Paint score of a website (if at all relevant, though I don't know how/why if we are just talking about page load, it's a Shopify website...). So I need to load the largest image on the screen quickly. And the loading isn't happening as I expect.
If we take this site as an example (this is not actually the site I am working on, but it seems to be happening on all the "larger" sites I've assessed. This one is Shopify too): https://www.luxyhair.com/
It has images (eg. //cdn.shopify.com/s/files/1/0066/0052/files/Homepage-Hero_1x1_Cool-Dark-Brown-Balayage_800x.jpg?v=1632412052) that are queued in the Network tab after JS scripts that are below it in the page source (eg. //cdn.shopify.com/s/files/1/0066/0052/t/207/assets/theme.min.js?v=18003517125669543370).
I'm not sure why this is happening.
<!doctype html>
<html lang="en">
<head>
....
<link href="//cdn.shopify.com/s/files/1/0066/0052/t/207/assets/theme.min.css?v=10166822434284191108" rel="stylesheet" type="text/css" media="all" />
....
</head>
<body class="theme-index">
....
<img class="one-whole" src="//cdn.shopify.com/s/files/1/0066/0052/files/Homepage-Hero_1x1_Cool-Dark-Brown-Balayage_800x.jpg?v=1632412052" alt="" />
....
<script src="//cdn.shopify.com/s/files/1/0066/0052/t/207/assets/theme.min.js?v=18003517125669543370" type="text/javascript"></script>
....
</body>
</html>
My fundamental confusion here is why the browser is queuing assets not in the order they are listed in the HTML source.
How I can get an image to load before a bunch of JS scripts that are in the footer that aren't as important? I know about <link rel="preload"> but I can't use that as the image is defined in a page section that's not available for me to capture until after the <head> of the page (because of how Shopify's section templating engine works). I've tried inserting a <link rel="preload"> into the with an inline script, but as expected that hasn't worked. I have also tried adding importance="high" on the img tag. That also hasn't worked.
I am currently at a dead end on one of the projects I am working on.
I'm working on the translation of an application in Xamarin Ios, at the moment
the entire application can be translated and the language of the application can be changed directly via the app.
But this application also has Tutorials pages that explain in a few words what is the purpose of this feature.
These pages are in html and have a relatively simplistic content that looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Tutorial 1</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div class="content-block">
<p>Use this page to add a new friend</p>
<p>It could be a good idea to give him a pseudo</p>
</div>
</body>
</html>
These pages should be translated on the fly when the user
decides to change the language of the application.
Currently the entire application could be translated into several languages except these html pages, simply because I have no idea what's the best way to do it.
I didn't find any information or documentation about this (I'm pretty sure that's because I'm using Xamarin Ios).
I am looking for a way to fill my html file with the contents of my resx files in which I would put the content html pages.
1 - I will have to save Html tags in my resx files if I decide to write <strong> this word </ strong>, which does not seem to me very practical and will oblige me to record every sentence and / or word that stands between specific tag ?
2 - How can I do this binding between my html file and my resx file? To get something like this
<!DOCTYPE html>
<html>
<head>
<title>Tutorial 1</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="viewport" content="width=device-width">
</head>
<body>
<div class="content-block">
<p> [contentFromMyResxFile] </p>
<p> [AnotherContentFromMyResxFile] </p>
</div>
</body>
</html>
content being loaded directly from my resx file and so could adapt to the language of the application.
I am writing a program that should include rather long text chunks in an html-file generated through jinja2. Because of a complex macro structure, I want to structure these texts as jinja2 variables, like so:
<!DOCTYPE HTML>
{% set standard_text = "This is the standard text." %}
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
{{standard_text}}
</body>
</html>
This works fine, but since these texts can be rather long, I want to have them in separate files. So I created a file called text.html:
{% set standard_text = "This is the standard text." %}
and put it into a library called templates/standard_texts. Now I want to import it into the html file and I have tried the following:
<!DOCTYPE HTML>
{% include 'templates/standard_texts/text.html' %}
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
{{standard_text}}
</body>
</html>
However, when I run this, I get this error:
jinja2.exceptions.UndefinedError: 'standard_text' is undefined
I have also tried other methods, such as
{% from 'templates/standard_texts/text.html import standard_text %}
or
{% extends'templates/standard_texts/text.html' %}
but that does not work either. I have read through Jinja2's "Template Designer Documentation" (http://jinja.pocoo.org/docs/2.10/templates/#), but I wasn't able to find anything there either.
How is this done?
It turns out that I made very silly error when testing option number two, using from ... import. There was an unmatched single quote, and with that fixed, it works. So corrected, the document looks like this:
<!DOCTYPE HTML>
{% from 'templates/standard_texts/text.html' import standard_text %}
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
{{standard_text}}
</body>
</html>
I'm having an odd issue with Django 2.0.4 (which maybe isn't so odd since I'm new to it).
I have a template which I am rendering from a view, and the data passed in is a string containing HTML.
My view renders the template as so:
return render(request, 'template.html', { 'data' : data })
data.content contains HTML in the above.
In my template, I am rendering it as so:
template.html (what works):
{{ data.content|safe }}
This renders fine. However when I have this template include other templates, the HTML ceases to render correctly.
template.html (what I want):
{% include 'header.html' %}
{{ data.content|safe }}
{% include 'footer.html' %}
The above renders header.html and footer.html fine, but the data.content|safe part in between actually becomes text with no styling. If I view source it's correct HTML (real tags, classes, etc. No & l t ; funny business.), but the browser doesn't apply rendering to it. It just winds up plaintext, e.g. strong tags around a word don't make it bold, lists are just linebreaks, etc. Even though the HTML in the top and bottom templates are included correctly with displayable HTML.
The oddest part is the only HTML that is rendered correctly from that variable is hrefs. Nothing else. I think it's crazy that no other tag works. There is no CSS messing with the HTML, either.
I have also tried using {% autoescape off %} ... {% endautoescape %} with the same results.
Obviously my intention here is to have my view display an HTML page composed of multiple templates, with values distributed among them. Yet I can't even get this one variable to display correctly, let alone any others.
Thank you so much for any help.
Edit:
header.html:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<meta name="Description" content="" />
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,600,600i,700|Open+Sans:300,400,400i,600,700|Roboto:300,400,400i,700|Arvo:400,400i,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{% static "org/css/foundation.min.css" %}"/>
<link rel="stylesheet" type="text/css" href="{% static "org/css/styles.css" %}"/>
</head>
<body>
template.html:
{{ data.content|safe }}
'data.content' is the string '<strong>test</strong>'
footer.html:
</body>
</html>
The resulting view source:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
<meta name="Description" content="" />
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,600,600i,700|Open+Sans:300,400,400i,600,700|Roboto:300,400,400i,700|Arvo:400,400i,700" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/org/css/foundation.min.css" />
<link rel="stylesheet" type="text/css" href="/org/css/styles.css" />
</head>
<body>
<strong>test</strong>
</body>
</html>
The resulting displayed HTML page is just 'test' with no strong styling.
After a few days of searching and trying to solve, got nowhere.
CKEditor 4.7.0 is stripping the content between the <title></title> tags. I need CKEDitor to leave the title content alone no matter how / where the title tag is used.
I have tried:
allowedContent: true,
extraAllowedContent : 'title',
extraAllowedContent: 'title[*]',
config.allowedContent = true; (in config.js)
CKEDITOR.dtd.$removeEmpty['title'] = false; (in config.js)
No luck with above. Then tried suggestion here ckeditor deteles page <title></title> title which works, but I end up with:
<!DOCTYPE html>
<html>
<head>
<title>OK Title</title>
</head>
<body> </body>
</html>
<p><br />
<title></title>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Web template presented with pure css."><meta name="keywords" content="css template"></p>
<link href="style.css" rel="stylesheet" />
<link href="red.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" /><!-- Header -->
<header class="w3-container w3-theme w3-padding" id="myHeader">
<div class="w3-center">
<h4>BEAUTIFUL RESPONSIVE WEB SITES</h4>
What I am doing is pasting into CKEditor an example CSS templates from https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_templates_black&stacked=h
I understand this is not the way standard HTML should be displayed (not to spec), but I need to prevent CKEditor from modifying the title tag no matter, just ignore it and let me use it wherever:) This is just a simple project for classroom where no one sees source of page and I need title tag to show in browser tab when I project page on whiteboard for students.
UPDATE: did discover if I save with the source in view, CKEditor does not modify the title tag. Works this way but not when in visual mode which like to have:)
After what seemed like endless searches found some info on a drupal forum. Had so many links open lost track of exact site where obtained the info, sorry.
Solved the problem by adding the following to my config.js in CKEditor 4.7.0:
config.allowedContent = true;
config.protectedSource.push(/<title>[\s\S]*?<\/title>/gi); // allow content between <title></title>
Hope this will help someone else:)