Я написал не большой код на Python для регистрации но когда человек приходит на главную страницу должен появится cookie_hash чего не происходит :((
import random
import hashlib
import sqlite3
from bottle import route, run, template, response, request
#configs and values
conn = sqlite3.connect('BlogsData.db')
c = conn.cursor()
# hashing password: hashlib.sha224("mypass").hexdigest()
# generate cookie hash: random.randrange(10000000000)
# For get and set cookie in bootle using:
# response.set_header('Set-Cookie', 'name=value')
# response.add_header('Set-Cookie', 'name2=value2')
# sqlte3 docs.python.org/2/library/sqlite3.html
# Save (commit) the changes
# conn.commit()
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
# conn.close()
# c.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
@route('/reg/<name>/<password>')
def index(name, password):
cookie_hash = random.randrange(10000000000)
response.set_header('Set-Cookie', 'cookie_hash=%s' % (cookie_hash))
c.execute("INSERT INTO UserData (login, password, cookie_hash) VALUES ('%s','%s', '%s')" % (name, password, cookie_hash))
conn.commit()
conn.close()
@route('/get')
def cookie():
print request.get_cookie("cookie_hash")
return request.get_cookie("cookie_hash")
@route('/hello')
def hello_again():
if request.get_cookie("visited"):
return "Welcome back! Nice to see you again"
else:
response.set_cookie("visited", "yes")
return request.get_cookie("visited")
run(host='localhost', port=8100)