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
Related
I need to test requests that can be sent through iframe. For example: i have some page on domain_01:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
body {
margin: 0 auto;
}
</style>
<body>
<iframe id="inlineFrameExample"
title="Inline Frame Example"
width="1600"
height="900"
src="http://domain_02:8000/app/dashboard">
</iframe>
</body>
</html>
And as you can see here this page contains iframe with link to page on domain_02. I try to understand: is it possible to emulate request that goes to domain_02 through this iframe on doamin_01 with pytest.
Main task what i need to solve it's create tests with different requests and check that there is no CORS issues with it.
How i check it now: manually only. I run second web-server through inner python server (python -m http.server 8090) and set dns-record on local dns-server to emulate domain_01. It will be so cool to run this tests with pytest.
css located in my_blog/my_blog/blog/static/blog/style.css
manage.py in my_blog/my_blog
head of html:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'blog/style.css' %}">
<title>{% block title%} My blog {% endblock %}</title>
</head>
I'm using pycharm pro. Browser successfully load css file, but it's empty. Why this is happenning?
I don't see css loading in django console log, when pages load. I changed name of css file. And it's loaded, but once.
When I add new rule to it and reload server, browser still get old version of css.
Now it's works fine. Css loaded properly. I didn't change anything, so I don't know what did happen.
Add this to your settings.py:
os.path.join(BASE_DIR, 'static')
Then move your static folder to project's folder - /my_blog/static/blog/style.css instead of the current one.
I don't believe your href is formatted properly
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>
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
I'd like to be able to download a HTML page (let's say this actual question!):
f = urllib2.urlopen('https://stackoverflow.com/questions/33914277')
content = f.read() # soup = BeautifulSoup(content) could be useful?
g = open("mypage.html", 'w')
g.write(content)
g.close()
such that it is displayed the same way locally than online. Currently here is the (bad) result:
(source: gget.it)
Thus, one need to download CSS, and modify the HTML itself such that it points to this local CSS file... and the same for images, etc.
How to do this? (I think there should be simpler than this answer, that doesn't handle CSS, but how? Library?)
Since css and image files fall under CORS policy, from your local html you still can refer to them while they are in the cloud. The problem is unresolved URIs. In the html head section you have smth. like this:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="/assets/8943fcf6/select.css" />
<link href="/css/media.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/assets/jquery.yii.js"></script>
<script type="text/javascript" src="/assets/select.js"></script>
</head>
Obviously /css/media.css implies base address, ex. http://example.com. To resolve it for local file you need to make http://example.com/css/media.css as href value in your local copy of html. So now you should parse and add the base into the local code:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="http://example.com/assets/select.css" />
<link href="http://example.com/css/media.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="http://example.com/assets/jquery.yii.js"></script>
<script type="text/javascript" src="http://example.com/assets/select.js"></script>
</head>
Use any means for that (js, php...)
Update
Since a local file also contains images' references throughout the body section you'll need to resolve them too.