I have a Django application where the logging is being printed to a file using the logging module.
I want to be able to have the contents of the log file also display on an html page such if a new line gets printed to the log page, the html page will also actively update to display the new line without having to be refreshed.
How can that be accomplished?
You need JavaScript for updating HTML without refreshing the page.
Create or edit the HTML with JavaScript and use AJAX for fetching latest logs every x seconds or how often you want the page to update. AJAX calls some Django view that returns the log data. For example, the view could read 10 latest lines from a log file and return that. JSON is probably the easiest format to work with but any format is fine (doesn't have to be XML like in the picture).
Tutorial for doing something like this with Django + jQuery
Depending on how complicated the logging page is, you may want to check out Django's documentation for JavaScript, storing JavaScript files in the project if JS code is not just in the HTML files, Django Rest Framework and different JavaScript libraries/frameworks such as React or Vue.
Related
I‘m using node.js, express and handlebars.
Currently I‘m passing json via res.render() to hbs. In the hbs I‘m using {{#each dataJson}} to iterate over it and list the contents of my json. Now... what if my json had like a million entries? It would take forever to load my page then, right?
Now to my Question:
How do I load that dynamic? I want the page to load the html from the json while showing what‘s already loaded.
Sorry for my bad english. It‘s not my native language.
Best regards
Naggelus
You would need to implement a lazy loading mechanism.
Instead of loading all the million records on the initial load, you would need to send it in chunks. Based on the view port, the records can be decided and load the first page. When the user goes over those records, you need send another API request to fetch the next chunk and so on.
This would load only the necessary records to the UI.
I am trying to create a webpage or page element that will read and display the data from an external XML data feed. I can't seem to find documentation on their site that will help and I am very new to this.
This is the XML url generated: https://spacedout.ampsuite.com/xml/releases?cid=2&s_date=2018-01-01&e_date=2019-01-11&order=release_date&dir=desc&limit=10
And this is an example of how I would like it displayed: https://client.ampsuite.com/
Pretty much just the section under "featured releases" that lists current music releases.
You can use wixCode backend function in order to do that. All you need is to use the wix-fetch API to get the data, then you can parse the XML using xml-js (which is a node module you can install in the backend).
In your client code you'll need to call your backend function and then inject the results to something like a repeater / table element on your UI.
Recently I've found that I can use pure HTML, CSS and JS to build Android app (and iOS also maybe), by using PhoneGap. I guess it converts HTML pages to Android web views. So basically I'll have ~10 HTML files, calling each other, get data from Server (it's Java and Tomcat) via Ajax and JSONP.
And my problem is about storing user data with these static local HTML files.
As they are local files, I can't use Cookie. But somehow Session's still working, so with each HTML page, I can set an onload event that sends an Ajax request, then get data. But it's very inconvenient, I have to do that for the same data each time I switch to another HTML file. So, is there any solution I can load all data when the first HTML file is loaded, store data somewhere, then reuse these data in others HTML files ? Thank you so much for reading my question.
So I want to create a chart using Google Chart API. The problem is following:
I need to create a chart which would use JSON data for the Output.
Example:
I am creating a BarChart which should show Montly Income. Each bar should represent X value of income. But this income changes monthly and I dont want to update the new numbers (as there are plenty) manually by writting them inside the JSON structure (I will use PERL scripts that will gather the new data).
I have read plenty on ther web, but all are using JSON COMBINED WITH PHP ! But I do not have a Web Server. What I want is to create a JSON FOLDER on my desktop, which will contain 100 JSON files inside it.
And when I browse my HTML page, I will click on Monthly Income (May) and this should open a new HTML page which should have some sort of INCLUDE or call function, which should call a SPECIFIC JSON file from the JSON folder on my computer that is coresponded with the path I have chosen on my webpage (in this case Monthly income (May)).
I think my problem is MORE SIMPLE than the method with PHP updating, because I am not worried with the updates - I will update my text files with PERL script. I just need a way, how to include a JSON file into my HTML script, without using PHP or any of these WEB SERVER related stuff.
Any ideas / suggestion ?
Thanks,
David
You can't reliably do it cross-browser with JSON because some browsers block ajax calls from local files (e.g., file:// URLs). But you can do it with JSON-P.
You create the files like this:
dataCallback(/*...JSON here...*/)
E.g.:
dataCallback({
"foo": "bar"
});
...and use this to load the relevant:
<script>
function dataCallback(data) {
// Here, the data will be the deserialized (parsed) data
}
</script>
<script src="/path/to/jsonp/file"></script>
Basically this is using JavaScript, rather than JSON, but where the data file although technically code is really just a function call with the data in the argument.
I have created a rrdcgi script to display information about the system performance with graphs. Now I would like to add an option for the users to create PDF on the fly with the details on current page (images and information) and header and footer. I also want the generated PDF files to be saved in some location so that that can be easily accessed next time. Is this possible to do with rrdcgi or any Perl code would be really appreciated.
I need this options
You need to consider what you want to put in the PDF: Do you want an exact replica of the web page the user is viewing (too hard to be close to impossible without having the user's browser installed on your side and using its print output) or do you want the same information in a roughly similar layout?
An important issue is how you are generating the HTML: I did something similar once to generate PDF receipts for experiment participants (now, I just output HTML with print styles).
The HTML is generated using HTML::Template although Template.pm would be just as fine.
It is then trivial to write another template, one that generates a LATEX document which can be processed using pdflatex. If you save the data the time the snapshot is requested, you can add the snapshot to a queue that generates documents asynchronously so that requests do not tie up the web server.
Update: Looking at rrdcgi, I now realize that it already does use a template. That is perfect: Instead of putting HTML in the template, put LATEX code in the template and run rrdcgi with the --filter option to create a LATEX source file which you can run through pdflatex. I guess the problem to solve there is to be able to use the exact same data that was used to generate the page the user is looking at.
If it is not possible to re-run rrdcgi with the exact same data, consider adding some JavaScript that submits the HTML source of the page the user is reviewing (or some JSON representation thereof) to a CGI script that parses the HTML and outputs LATEX. Writing clean HTML in the original template and judicious use of class and id attributes would help there.
I do not have time to test any of these ideas right now, but I will take a look again within the next couple of days.
Is it worth the effort?
Why don't you add a FAQ explaining how to setup a PDF-printer on Windows/MAC/Linux and provide a 'clean' page that can then be printed?
Since you apparently have to create the PDF,
take a look at this (what-is-the-best-perl-module-to-use-for-creating-a-pdf-from-scratch) post here on SO.
There is also this post, that could combine the 'clean' HTML page and a server-side print.
Regarding the LaTeX route, if you have rrdcgi generate graphs in pdf format, pdflatex will be able to integrate them directly into the document, producing super quality pdf with graphs ... very slick. Sorry, no code.