buttons do something

26 views
Skip to first unread message

dk

unread,
Oct 4, 2014, 12:46:44 AM10/4/14
to django...@googlegroups.com
I am trying to put some user input into a table.   after the user select a radio button the option the want,  the should click a button for submitting the information to the database, and display a message, or go to another website,
I am so use to PyQt where you just connect the signal with the function you want.     is there anything like that in django?

this is my view that construct the webpage.  I also submitted a picture of how the webpage should look like
def vote(request):
    django.setup()

    response = HttpResponse()
    response.write("<html><body>\n")
    response.write("<p>Vote for the restaurant of your choise</p>\n")

    response.write("<fieldset>")

    response.write("<legend><strong>Restaurant:</strong> </legend>")

    response.write('<table border="1" style="width:100%">')
    response.write('<form action="">')
    all_restaurants = Restaurant.objects.all()
    for i in all_restaurants:
        #link = "<a href=\" Restaurant_Info/%d\">" %(i.id)
        #response.write("<li>" + link + i.name + "</a></li>")
        response.write("<tr>")
        response.write("<td>")
        response.write('<input type=\"radio" name="restaurant" value='+i.name+'>'+i.name+'<br>')
        #response.write('<input type=\"radio" name="restaurant" value='+i.id+'>'+i.name+'<br>')
        response.write("</td>")

        dishes_per_restaurant = Dish.objects.filter(restaurant_id=i.id)
        for j in dishes_per_restaurant:
            response.write("</td>")
            response.write("<td>"+j.name+"</td>")
        response.write("</tr>")

    response.write("</table>")
    response.write("</form>")
    response.write("</fieldset>")

    response.write('<button type="button" onclick="alert(\'Hello world!\')">Click Me!</button>')
    response.write("</body></html>")
    return response


thanks =)

django.png

Collin Anderson

unread,
Oct 4, 2014, 1:16:48 PM10/4/14
to django...@googlegroups.com
The simple way is to use <input type="submit" value="Click Me!"> before your </form>.

The other option is to submit the data by hand using javascript.

I also recommend checking out templates, if you haven't looked at them:
Reply all
Reply to author
Forward
0 new messages