skip to Main Content

I have a front end webpage using html, css and js. I also have a back end using python code. The project is basically a URL Shortener Website. How can I connect the front-end with the back-end without a database and without using flask in python?

#my back-end code

import pyshorteners

import pyperclip

link=input("Enter the link: ")

shortener=pyshorteners.Shortener()

x=shortener.tinyurl.short(link)

print(x)

pyperclip.copy(x)

#the input in the textbox on front-end should be transferred to the back-end and stored in the variable "link". How can I achieve that? The shortened URL should also be sent back to the front end.

We tried using flask but since it was an absolutely new topic, we were unable to implement it. I couldn’t understand importing "templates" file in flask. Hence, the template of website was not loaded properly and the code showed error.

I dont know how to integrate Django or Nodejs. If the solution requires adding of these, then how can I install or import them?

2

Answers


  1. You have to create client-server model,

    1. You can create an API using flask or django. Follow this Create API.

    2. Call the API using front-end (HTML,Javascript). Refer this Access API

    Login or Signup to reply.
  2. Python has been compiled to WASM, so you can use Python in the browser, see https://pyodide.org/en/stable/

    Pyodide makes it possible to install and run Python packages in the browser with micropip.

    Alternatively a Python Native Messaging host could be used to avoid using servers at all, the code will be run on the users’ machine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search