vendredi 15 juin 2018

python:when i input something it resets the url

*excuse me if i couldn't describe what exactly i mean in the title i can't find the accurate words

anyway i am new to web developing , i am taking a course , it made a shopping list which , in brief , allows the user to add food and display whatever he enters but my problem is when i enter new food the url resets only with the new input

my code

import webapp2
import jinja2
form = """<form>
<input name = 'food' type = 'text'>
%s
<button>Add</button>
</form>"""
hidden_html = """
<input type = "hidden" name "food" value = "%s">
"""

item_html = "<li>%s</li>"

shopping_list_html = """
<br>
<br>
<h2>Shopping List</h2>
<ul>
%s
</ul>
"""

class MainPage(webapp2.RequestHandler):
def write(self , *args , **Kargs):
    self.response.out.write(*args,**Kargs)

def get(self):
    output = form
    hidd = ""

    items = self.request.get_all("food")
    if items:
        output_items = ""
        for item in items:
           hidd += hidden_html % item
           output_items += item_html % item
        output_shopping = shopping_list_html % output_items
        output += output_shopping
    output = output % hidd

    self.write(output)
def post(self):
    self.write("happy birthzeft")

app = webapp2.WSGIApplication([
('/', MainPage)
], debug=True)

output




Aucun commentaire:

Enregistrer un commentaire