开发者

python database search with html

I have created a d开发者_运维知识库atabase with python and the results are kept in a text file. I would like to create a simple html with a search button that looks through my database. My database would be accessible only on my computer.

My database looks something like this:

Reference | Name | Dimension
XXX         AAA     45

So, for example, if I search for a specific reference I would like to obtain their name or dimension obviously.

Is this even possible with python and where do I start ? I should mention I have basic skills in html and python.


There are multiple ways to solve this:

  • Install a webserver on your local machine and write a full-fledged Python web application
  • Write a simple webserver and application in Python using BaseHTTPServer
  • Write an HTML/JavaScript application that doesn't use Python at all and parses the file for itself. Note that due to recently tightened restrictions, this may still require being served by a webserver.
  • Write a Python application that writes the database to a JavaScript file. While this is inflexible (you need to run it every time you want to update the database), it's also very simple - just encode your data with JSON and write it in a JavaScript file or element, like this.

htmlfile = open('database.html', 'w')
htmlfile.write('<html>...')
htmlfile.write('<script>var db = ' + json.encode(database) + ';</script>');

Either way, you're going to have to write HTML and JavaScript.


You have a very simple use case and if you already have a web server installed, then probably the simplest and quickest way is to use a CGI script written in python. Check out the cgi module: http://docs.python.org/library/cgi.html.

Basically you have to handle GET request to show a HTML form for asking the query string and the POST request to process the query and show the results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜