0
I'm trying to make an input box and a submit button on a forum that uses my python calculator. Do I need a server? How doidoit?
Im following two different pyscript button tutorials. One shows me how to make the box (4th one) the other(first 3) how to add functionality to the submit button. When i test it in browser it says it cant access my file only other types. So i hear i may need a server? I know very little about html. Im using Flask and sublime. A sample input would be GUARD1 enter 1 enter OPEN enter https://code.sololearn.com/crCGZhMmV6BE/?ref=app https://code.sololearn.com/WKW7IMZhJ390/?ref=app https://code.sololearn.com/cT9Y981anJ5I/?ref=app https://code.sololearn.com/WABp7oXR3gTv/?ref=app
6 Antworten
+ 2
It is very confusing what you are trying to do here, and most importantly, HOW.
https://en.m.wikipedia.org/wiki/Client%E2%80%93server_model
Flask is a web application framework that assumes a client-server architecture. The Python code runs on a web server and responds to client calls that are made in the client web browser, typically through REST API or similar techniques. The client side is only HTML page, typically created by some templating solution, in case of Flask that would be Jinja2.
On the other hand, Pyscript lets you run Python code on the client side, through the power of webassembly (WASM). This solution does not require any servers. But you would embed your python code directly in the html page.
You cannot run a Flask application in the Sololearn playground, but it is possible to experiment with Pyscript in the web playground.
+ 2
Related to your cross origin error, the index.html is really small and the only thing in it that can cause this error, is importing jquery.
Maybe you are refering to a server based on old tutorials, where this is no longer allowed for security reasons. Try linking your script to a CDN (content delivery network).
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
About the popup / browser prompt window that appears in your pyscript code, I am not sure what is causing it, your code is too long for me to review right now. Maybe I will have time to check another day.
+ 1
Tibor Santa what youve said so far is the path im on. Me and my friend have a forum page and i want to put myscipt on it cleanly with an html input box and a submit button to run myscript.py currently i can succesfully put myscript.py on the forum but only with no html button or box. (Box help - the extra html) my only issue with that is you have to type everything in a random pop up alert box.
+ 1
If i run index.html in browser myscript.py throws an error (f12 then over to console) that says 'access to index.html -> myscript.py from origin null has been blocked by CORS policy; cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted'
+ 1
My goal was to stop the python/web alert box from popping up and to use the html box and button instead. In 'box help' you can run and see how the html box isnt linked to my python in any way. this is the tutorial im following with the first 3 https://youtu.be/0meTbQQaosU
0
Its just the standard python input box like "website says: [box]" . i think youre on to something with security issues. Thanks ill check out what you posted.
update- same error
update- im going to re ask with new code
update- code slowly morphed into the server way. never found the right pyscript to run my code. would prefer pyscript, thats how im doing it now but with no form. in visual studio code i can get my html to access and display my python file using flask but not on the forums and id rather use pyscript anyway. Its like i just need to pass them the form inputs and run the code?