Last active
November 7, 2019 11:44
-
-
Save abdelouahabb/01c7c88fed65d119d6b8 to your computer and use it in GitHub Desktop.
Revisions
-
abdelouahabb revised this gist
Jun 21, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ class Getter(tornado.web.RequestHandler): def get(self): c.execute('select * from users') res = c.fetchall() #search about fetchmany(int), fetchone() to get only some records or one (note that after getting it, the cursor will increment) resultat = [] for i in res: resultat.append(i) -
abdelouahabb revised this gist
Jun 21, 2014 . 2 changed files with 25 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,21 +7,32 @@ c = conn.cursor() try: c.execute('''CREATE TABLE users (nom text, prenom text, age int)''') except sqlite3.OperationalError: pass class BaseHandler(tornado.web.RequestHandler): def get(self): self.render('page.html') class Saver(tornado.web.RequestHandler): def post(self): nomm = self.get_argument('nom') pren = self.get_argument('prenom') age = int(self.get_argument('age')) c.execute("insert into users values (?, ?, ?)", (nomm, pren, age)) conn.commit() self.redirect('/success') class Getter(tornado.web.RequestHandler): def get(self): c.execute('select * from users') res = c.fetchall() #fetchmany(int), fetchone() resultat = [] for i in res: resultat.append(i) self.write(str(resultat)) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,9 +8,16 @@ <body> <form action='/toz' method='post' > {% raw xsrf_form_html() %} Nom <input type='text' name='nom'> Prenom <input type='text' name='prenom'> Age <input type="number" name='age'> <input type='submit'> </form> </body> </html> -
abdelouahabb revised this gist
Jun 21, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Recup(tornado.web.RequestHandler): def post(self): nomm = self.get_argument('nom') print nomm c.execute("insert into users values (?)", (nomm,)) conn.commit() conn.close() -
abdelouahabb revised this gist
Jun 21, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import tornado.web import tornado.httpserver import tornado.ioloop from tornado.options import define, options import handlers import os -
abdelouahabb created this gist
Jun 21, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ #!/usr/bin/env python #-*- coding:utf-8 -*- import tornado.web import tornado.httpserver import tornado.ioloop import tornado.options from tornado.options import define, options import handlers import os define("port", default=8000, type=int) urls = [ (r"/", handlers.BaseHandler), (r"/toz", handlers.Recup), (r"/(.*)", tornado.web.StaticFileHandler, {"path": r"{0}".format(os.path.dirname(__file__))}) ] settings = dict({ "template_path": os.path.join(os.path.dirname(__file__), "templates"), # create a folder templates and put the html file there #"static_path": os.path.join(os.path.dirname(__file__), "static"), # if there is static files, uncomment this. "cookie_secret": str(os.urandom(45)), "xsrf_cookies": True, "debug": False, "gzip": True, }) application = tornado.web.Application(urls, **settings) if __name__ == "__main__": server = tornado.httpserver.HTTPServer(application) server.listen(options.port) tornado.ioloop.IOLoop.instance().start() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #coding: utf-8 import tornado.web import sqlite3 conn = sqlite3.connect('c:/toz.db') c = conn.cursor() try: c.execute('''CREATE TABLE users (nom text)''') except sqlite3.OperationalError: pass class BaseHandler(tornado.web.RequestHandler): def get(self): self.render('page.html') class Recup(tornado.web.RequestHandler): def post(self): nomm = self.get_argument('nom') print nomm c.execute("insert into users values (?)", (nomm)) conn.commit() conn.close() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <form action='/toz' method='post' > {% raw xsrf_form_html() %} Toz<input type='text' name='nom'> <input type='submit'> </form> </body> </html>