index.html
{{if auth.user:}}
{{=A('create new survey',_href=URL('create_survey'),_class="btn btn-primary")}}
{{=grid}}
{{else:}}
Welcome to this survey app, login or register to create a survey
{{pass}}
default.html
def create_survey():
def f(form):
form.vars.results = [0]*len(request.vars.choices)
from gluon.utils import web2py_uuid
db.survey.uuid.default = uuid = web2py_uuid()
form = SQLFORM(db.survey).process(onvalidation=f)
if form.accepted:
redirect(URL('take_survey',args=uuid))
return locals()
def take_survey():
uuid = request.args(0)
survey = db.survey(uuid=uuid) or redirect(URL('index'))
if survey.requires_login:
if not auth.user:
redirect(URL('user/login',vars=dict(_next=URL(args=uuid))))
vote = db.vote(survey=survey.id,created_by=auth.user.id)
if vote:
session.flash = 'You voted already!'
redirect(URL('thank_you'))
if request.post_vars:
k = int(request.post_vars.choice)
survey.results[k]+=1
survey.update_record(results=survey.results)
if survey.requires_login:
db.vote.insert(survey=survey.id)
redirect(URL('thank_you'))
return locals()
in local its working properly...tested this code in "pythonanywhere.com" site ..its not working..got below error
invalid view (default/create_survey.html)
how to solve this issue?any one can you help me....
[edit by admin: code formatting]