1

I have created a database 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.

2 Answers 2

3

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.

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

2 Comments

Alternative to the first option: write a simple webserver in Python, using the HTTP server in the standard library. Examples are all over the web, for example, fragments.turtlemeat.com/pythonwebserver.php
@Balir Thanks - integrated into the answer.
1

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.

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.