Home > other >  Ask bosses told to help me see about tuples index of scope
Ask bosses told to help me see about tuples index of scope

Time:10-07

, commercial himself in do you make a reservation system to add an address, is able to run normally, before and after he remind me tuples index out of range, I find out the problem of the line but I don't know how to change, who teach me, the code is as follows:
Def payment_movie (request) :
If not request. Session. Get (' is_login, None) : # not login cannot see
Return redirect ('/login ')

# accept request parameters inside the
. If the request method=="POST" :
NeedNum=request. POST. Get (' num ')
NeedName=request. POST. Get (' name ')
NeedDate=request. POST. Get (' date ')
NeedAdd=request. POST. Get (" address ")

The username=request. Session. Get (" user_name ")
# to determine whether input digital
Try # use to judge whether the input is digital
Try:
NeedNum=int (needNum)
Except:
Return an HttpResponse (" the votes than digital input ")

How much of the rest of the ticket # query database
Get_sql="select movie_residue FROM movie_site_n where movie_name='{}' and movie_date='{}' and movie_address". The format (needName needDate, needAdd)

NowResidue=int (get_sqldata (get_sql) [0] [0] [0])

# rest after calculating the purchase ticket
ResResidue=int (nowResidue) - int (needNum)

If resResidue & lt; 0:
Return an HttpResponse (" I'm sorry, ticket only {}, unable to meet your needs in {} zhang ". The format (nowResidue, needNum))

# splicing update database SQL
Update_sql="UPDATE ` movie_site_n ` SET ` movie_residue `='{}' WHERE ` movie_name `='{}' AND ` movie_date `='{}' AND movie_address='{}';" \
. The format (STR (resResidue), needName needDate, needAdd)

# execute SQL
# with try catch exceptions, used to throw the payment failure
Try:
Insert (update_sql)
Except:
Return an HttpResponse (sorry, buy failure, "")

# # query whether in can change table, in words deleted, let he cannot change
Select_sql="select * from movie_site WHERE movie_name='{}' AND movie_date='{}' AND movie_address='{}'". The format (needName needDate, needAdd)
If not get_sqldata (select_sql)==() :
Delete_sql="delete FROM movie_site WHERE movie_name='{}' AND movie_date='{}' AND movie_address='{}'". The format (needName needDate, needAdd)
Insert (delete_sql)

For I in range (0, int (needNum) :
Insert_sql="INSERT INTO ` movie_personage ` (` name `, ` movie_name `, ` movie_date `, ` movie_address `)" \
"VALUES (' {} ', '{}', '{}', '{}');" . The format (username, needName needDate, needAdd)
Insert (insert_sql)

# splicing in json format film name, time and buy votes
NeedRes={}
NeedRes [' name ']=needName
NeedRes [' date ']=needDate
NeedRes [' num]=needNum
NeedRes [' address ']=needAdd

Return render (request, 'payment_movie. HTML' {' needRes: needRes})
  • Related