Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:32:19+00:00 2026-05-30T21:32:19+00:00

I have a simple voting webpage, where user is presented with a table with

  • 0

I have a simple “voting” webpage, where user is presented with a table with three columns. Each column will contain results of a search engine query, then user will choose which column has the better result and click a button.

Here is a sample: http://jsfiddle.net/rfeGa/

I need help with the following:
1. How do I keep track of the votes between the html page and python program?
2. I want to keep the list of queries in the python file, how do I pass that info over to the webpage?

Here is my html page:

<!DOCTYPE html>
<html>
    <head>
        <title>Search Engine Comparator!</title>
    </head>
    <body>      
        % queries = ("ccny", "bmcc", "qcc");
        % bingScore = googScore = yhooScore = 0;        
        % for q in queries:
        The query is: {{ q }}
        <br />
        And the scores are: Bing = {{ bingScore }}, Google = {{ googScore }}, Yahoo = {{ yhooScore }}.
        <hr>    
        <form action="/" method="post">
            <table border="1" width="100%">         
                <tr>
                    <th>
                        <input type="submit" name="engine1" value="Engine 1 is better!" />
                    </th>
                    <th>
                        <input type="submit" name="engine2" value="Engine 2 is better!" />
                    </th>
                    <th>
                        <input type="submit" name="engine3" value="Engine 3 is better!" />
                    </th>       
                </tr>
            </table>
        </form>
        % end
    </body>
</html>     

<script type="text/javascript">

</script>

Here is my python code:

from bottle import request, route, run, view
from mini_proj import *

@route('/', method=['GET', 'POST'])
@view('index.html')
def index():
    return dict(parts = request.forms.sentence.split(),
                show_form = request.method == 'GET');

run(host = 'localhost', port = 9988);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:32:21+00:00Added an answer on May 30, 2026 at 9:32 pm

    You can use jquery + mod_WSGI to let Python be the backend to a Javascript front end. You can push a result back to the Python script and let it modify a database for example. Here are some simplified portions of the solution. I left out a couple of details.

    I’m not familiar with bottle, but I have used web.py in the past to help accomplish this.

    I modified your jsfiddle to use the basic parts from the below jquery. Your javascript will pass back which button was clicked.

    <script type="text/javascript">
    
    jQuery(document).ready(function() {
    
        jQuery("input ").click(function() {
    
            // this captures passes back the value of the button that was clicked.
            var input_string = jQuery(this).val();
            alert ( "input: " + input_string );
    
            jQuery.ajax({
                type: "POST",
                url: "/myapp/",
                data: {button_choice: input_string},
            });
        });
    });
    
    </script>
    

    And let your python script modify a database in the backend .

    and here is using web.py , to grab inputs from jQuery
    import web
    import pyodbc

    urls = ( '/', 'broker',)
    render = web.template.render('/opt/local/apache2/wsgi-scripts/templates/')
    
    application = web.application(urls, globals()).wsgifunc()
    
    class broker:
        def GET(self):
            # here is where you will setup search engine queries, fetch the results 
            # and display them
    
            queries_to_execute = ...
            return str(queries_to_execute)
        def POST(self):
            # the POST will handle values passed back by jQuery AJAX
    
            input_data = web.input()
    
            try:
                print "input_data['button_choice'] : ", input_data['button_choice']
                button_chosen = input_data['button_choice']
            except KeyError:
                print 'bad Key'
    
    
            # update the database with the user input in the variable button_chosen
    
            driver = "{MySQL ODBC 5.1 Driver}"
            server = "localhost"
            database = "your_database" 
            table = "your_table"
    
            conn_str = 'DRIVER=%s;SERVER=%s;DATABASE=%s;UID=%s;PWD=%s' % ( driver, server, database, uid, pwd ) 
    
            cnxn = pyodbc.connect(conn_str)
    
            cursor = cnxn.cursor()
    
            # you need to put some thought into properly update your table to avoid race conditions
            update_string = "UPDATE your_table SET count='%s' WHERE search_engine='%s' "
    
            cursor.execute(update_string % (new_value ,which_search_engine)
            cnxn.commit()
    

    Your python file calls called using mod_WSGI. Take a look at how to set up Apache + mod_WSGI + web.py backend like i have described in a previous answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say i have a simple table voting with columns id(primaryKey),token(int),candidate(int),rank(int). I want to
So I have a simple voting feature on my asp.net mvc page. My index
Have simple Spring Security webapp with password encoding: <security:authentication-manager alias=authenticationManager> <security:authentication-provider user-service-ref=personService> <security:password-encoder hash=md5
I have a very simple voting form. It contains a single text field for
i have simple table with two fields: ID and Date how can i do
I have simple user registration form. In which i am puting city as a
I have a simple poll site. I would like to disallow possibility of voting
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.