I
I
Io67712022-04-02 16:52:23
Python
Io6771, 2022-04-02 16:52:23

How to add JSON for regular HTMl page?

Good afternoon!
I have a static Html page to which I need to connect Json so that when accessing it via requests.get
I could get an array of Json
Please help

me import urequests as requests
import json
response = requests.get("site")
Variable = json.loads(response.text)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Nesterov, 2022-04-02
@Io6771

1. You can't run python directly from html/js.
2. You can use js ( xmlhttprequest )
3. If it's important to use python, you can use a server written in python:
3.A: A simple self-written server (google for help).
3.B: Use the ready library:

  • flask + jinja2 (optimal for "one-liner")
  • django
  • fastAPI

T
true, 2022-04-03
@RAFAILgaley

the page can refer to any external script
, including the one that lies locally,
create a script element and specify the path to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question