+7

Displaying Form Data in Browser via Python

In php we use <form autocomplete="off" method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"> <input type="text" name="text"/> <input type="submit" /> </form> <?php $text = $_POST["text"] ; $text = htmlspecialchars($text); if(!empty($text)){ echo "<h1>$text</h1>"; } ?> to display form data in browser. but i want to do that same thing with pure python. Is this possible?

1/10/2019 12:26:51 PM

Tarek Monowar

18 Answers

New Answer

+8

Tarek Monowar You can't. You are talking about forms in a web browser. Browsers cannot interpret python language and the user interface where the forms are entered, are written in HTML. Thus you do NEED to use a web framework.

+7

I'm sure you can do this with Python Django framework

+5

Some resources where you find more detail. Django and Flask are both individual web frameworks for python. https://docs.djangoproject.com/en/2.1/topics/forms/ http://exploreflask.com/en/latest/forms.html

+4

HonFu Thanks, That moment, i had no idea,what title should i use. Btw,my question is unanswered :-(

+4

Tarek, The answer is to go through a web framework such as Django (as sugessted by most of the comments). Unfortunately you cannot use raw python code collect form data effectively. Thes the backend (like php) it is stored on the server. Django is very useful for projects like blogs, web apps, ect. Although I don't recommend starting to learn the Django library yourself because in itself it can be kind of confusing (based of of personal experience). If you want to implement the python into web development, I recommend going through a tutorial on the Django framework, such as this one: https://m.youtube.com/playlist?list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p ______________ Hope this helps

+3

An actual programming-related question, hallelujah! :) Your title suggests something else though, one of the many, many unanswerable questions like 'Which is better, Python or PHP?' So in order to get seen, you might want to change your title to something more specific.

+3

Tarek Monowar, unfortunately haven't learned web programming myself yet. I'm sure someone will help you!

+3

You will have to use a framework. Cherrypy is a lightweight framework. It is as easy as. pip install CherryPy import cherrypy class HelloWorld(object): @cherrypy.expose def index(self): return "Hello World!"

+2

perfect!

+2

Tarek Monowar, by the way. If you find django too difficult you can go through flask, (which is like a baby django)

+1

I wanna use python

+1

thank you zang :-)

0

HonFu Ohh, Thanks :-)

0

Tibor Santa Ohh,Ok. Thanks

0

zang yeah, nowadays, python is popular for web development. So,i wanted to use pure python. But now i see,that's not possible. now django is last hope

0

thank you Louis

-1

Tibor Santa but i want to do this in pure python. Not using by framework

-1

just trying to think i want to use pure python