0

Is it possible to embed a python script into HTML? For example:

name = input("What is your name?")
print("Hi, " + name)

If so, can it use modules, for example datetime, os, sys, random?

3
  • What purpose is this for? Why do you need those particular modules? Would another language work instead? Commented Jun 7, 2016 at 18:53
  • 1
    Search for: "python for web" or anything related. useful link: docs.python.org/2/howto/webservers.html Commented Jun 7, 2016 at 18:53
  • See Rosetta which lets you say <script type="text/x-python"> Commented Jun 7, 2016 at 20:15

1 Answer 1

3

If I'm understanding your question correctly, you'd actually do the opposite. You would serve HTML from your Python script. You could use whatever modules you like in your Python application along with whatever modules are necessary for you to serve HTML content.

There are many web frameworks for doing such. Django is perhaps the most popular but it may be too robust for what you want to do.

Perhaps check out Flask?

edit: Not to mention Python has a built-in method for serving up web content, Python WSGI (Web Server Gateway Interface), you can read more about Python WSGI here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.