brython "Uncaught ReferenceError: brython is not defined at onload" - python

hey guys and girls :) hope you can help me :)
im trying to run brython but for some reason i just get
"uncaught ReferenceError: brython is not defined
at onload" . i did try it with local installation and i tried to use the CDN source files.
and on both i get the same result.
now basically i just copied from the documentation some simple sample just to get it work :)
i did brython-cli -update
and im currently running a 3.10.3 version
in local.
but even with the CDN import script it just didnt work
im rendering the html file through flask and running flask server(maybe its just that, have no idea).
<head>
<meta charset="utf-8">
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
</head>
<body onload="brython()">
<h1>{{time_left}}</h1>
<script type="text/python">
from browser import document
document <= "Hello !"
</script>
</body>

Related

JsException(TypeError: Failed to fetch)

When I try to import a pyscript source code to my HTML it shows a "JsException(TypeError: Failed to fetch)" error.
helloworld.py
print("Hello World")
testPyscript.html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<title></title>
</head>
<body>
<py-script src="helloworld.py">
("Another Text Test")
</py-script>
</body>
</html>
I was having the same problem and found the answer here: PyScript: Loading Python Code in the Browser
The problem is <py-script src="helloworld.py"> do not support loading local files, you need a server for the browser to load it...
Go into the folder you keep the files and run python -m http.server 80 and then, on the browser, go to localhost/testPyscript.html
Hope it helps
For some reason your directory which contains helloworld.py and testPyscript.html need to run in localhost, open your folder in vsCode and install live server from extensions then in your right bottom corner press on Go Live. you will be directed to the default browser with the expected output from helloworld.py

Splash not parse JS before returning HTML response

in my crawler consisting of Scrapy and a Splash server I am having problems on this site: https://www.lavoropiu.it/offerte
The problem is related to Splash downloading the site's HTML without parsed JS. The site is an Angular app.
I have tried with different splash settings:
splash.private_mode_enabled = false
splash.js_enabled = true
The returned HTML is this:
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>Lavoropiu</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/chphsalvo/front-end-framework#0.9.3/dist/css/style.min.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script type="text/javascript" async="" src="https://www.google- analytics.com/analytics.js"></script><script async="" src="https://www.googletagmanager.com/gtag/js?id=UA-173597693-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-173597693-1', { send_page_view: false});
</script>
<link rel="stylesheet" href="styles.66ab468982a30141059e.css">
</head>
<body>
<script src="runtime.d6c52737d4587c65265f.js" defer=""></script>
<script src="polyfills.f782e0cdb7e1242a13e4.js" defer=""></script>
<script src="vendor.82696fd86eeed5072685.js" defer=""></script>
<script src="main.076dbf684e565ed2798b.js" defer=""></script>
<app-root></app-root>
</body>
</html>
As you can see Splash does not execute the scripts on the page before returning the HTML.
Is this an issue related with Splash or I am missing some setting?
Thanks for your help.
Splash fails to load the javascript. This is a common problem encountered when doing scraping with Splash. Check the issue page of Splash and do some searching, there's a lot report about the javascript loading problem.
The default engine for Splash is Webkit. It behaves differently with common Web browser engines in Chrome, Firefox. For web scraping, you'd better choose headless Chrome to download pages with javascript.
For async integration with scrapy, try playwright, or puppeteer. The former has a scrapy plugin scrapy-playwright, which is currently maintained.
Update: Scrapy API render.html has support for switching engine to "chromium". But it's experimental. You can have a try.

Python Eel. Python function does not start using from javascript

Sorry for my English.
I am want to study python library (eel). I am wrote the following code as in the example from the documentation:
The "index.html" file is located in the "Web" folder:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello</title>
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript">
eel.python_func("Hello from Python");
</script>
</head>
<body>
Hello!!
</body>
</html>
The "main.py" file is located one level above the "index.html" file:
import eel
eel.init("web")
#eel.expose
def python_func(text):
print(text)
eel.start("index.html")
Running main.py displays a browser window that says "Hello !!" but python_func() dont started. Message "Hello from Python" dont displayed in terminal.
I am tried different options for solutions to problem:
reinstalled eel
reinstalled python
pasted the python_func () function code right after import.
But this solutions not helped.
I ask for help in solving my problem.
I am using Python 3.7.6 32 bit

django-wysiwyg-redactor's RedactorField

I'm using django-wysiwyg-redactor and I have two question
How can I send RedactorField input to the template as a field in the form?
I'm using django-modeltranslation as well, but in admin site other language fileds for redactor input is ordinary
TextField.screenshot How can I fix this?
I believe that there should be some easy ways for my problems. Thanks in advance
Use this FAQ https://imperavi.com/redactor/docs/how-to-install/.
To install Redactor, place the following code between the <head></head> tags:
<link rel="stylesheet" href="/js/redactor/redactor.css" />
<script src="/js/redactor/redactor.js"></script>
If your Redactor download is placed in a different folder, don't forget to change file's paths.
You can call Redactor using the following code:
<script type="text/javascript">
$(function()
{
$('#content').redactor();
});
</script>

Jinja2 browser load

I am able to execute the python file through shell like so:
$ python jinja.py
[code]
from jinja2 import Environment, FileSystemLoader
DIR = '/Users/username/Sites'
env = Environment(loader=FileSystemLoader(DIR))
templateVars = {
"title" : "Test Example",
"description" : "Description"
}
template = env.get_template('index.html')
print template.render(templateVars)
[/code]
Here is the ouput via the shell:
[code]
<html>
<head>
<title>Test Example</title>
<meta name="description" content="Description">
</head>
<body>
test dictionary
</body>
</html>
[/code]
However, when I pull up index.html on the browser it doesn't render the variable, I am not sure the file jinja.py is even being executed.
Here is the sourcecode directly from my the browser window:
[code]
<html>
<head>
<title>{{ title }}</title>
<meta name="description" content="{{ description }}">
</head>
<body>
test dictionary
</body>
</html>
[/code]
Fyi, I am not using jinja2 in conjunction with any frameworks or other package dependencies.
Anyone able to help out.
Thanks
Mark
Your http://www.example.com/index.html should GET a script, which uses jinja to render the HTML.
You need a framework like webapp2 in Google App Engine to handle the GET.
I found this tutorial: https://www.youtube.com/watch?v=XyGW0ExGHDQ
Or use: https://developers.google.com/appengine/docs/python/gettingstartedpython27/introduction

Categories