librelist archives

« back to archive

ValueError

ValueError

From:
jaudat hussain
Date:
2012-09-09 @ 08:43
Hi, i recently decided to learn flask and mongodb using mongoengine, but i
am having trouble with my signup page here is the code:

@user.route('/signup/', methods=['GET', 'POST'])
def signup():
    if request.method == "POST":
        if request.form['password'] == request.form['verify']:
            new = Profile(email=request.form['email'],
password=request.form['password'])
            try: new.save()
            except Profile.NotUniqueError:
                render_template('signup.html', eerror="Email is already
taken", verror="", perror="")
            except ValidationError as e:
                render_template('signup.html', eerror="Email is of
incorrect format", verror="", perror="")
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('welcome'))
        else: render_template('signup.html', verror="Passwords do not
match", eerror="", perror="")
    else: render_template('signup.html', verror="",perror="",eerror="")

for some reason i keep getting the following:
ValueError: View function did not return a response

I am confused, any help will be appreciated.

Re: ValueError

From:
jaudat hussain
Date:
2012-09-09 @ 09:04
nevermind i fixed it, also there were some other small problems with my
code that i think i got working, need to test it more throughly tho. Thanks
guys and sorry for wasting your time :)

On Sun, Sep 9, 2012 at 4:43 AM, jaudat hussain <sjh.jaudat@gmail.com> wrote:

> Hi, i recently decided to learn flask and mongodb using mongoengine, but i
> am having trouble with my signup page here is the code:
>
> @user.route('/signup/', methods=['GET', 'POST'])
> def signup():
>     if request.method == "POST":
>         if request.form['password'] == request.form['verify']:
>             new = Profile(email=request.form['email'],
> password=request.form['password'])
>             try: new.save()
>             except Profile.NotUniqueError:
>                 render_template('signup.html', eerror="Email is already
> taken", verror="", perror="")
>             except ValidationError as e:
>                 render_template('signup.html', eerror="Email is of
> incorrect format", verror="", perror="")
>             session['logged_in'] = True
>             flash('You were logged in')
>             return redirect(url_for('welcome'))
>         else: render_template('signup.html', verror="Passwords do not
> match", eerror="", perror="")
>     else: render_template('signup.html', verror="",perror="",eerror="")
>
> for some reason i keep getting the following:
> ValueError: View function did not return a response
>
> I am confused, any help will be appreciated.
>

Re: [flask] ValueError

From:
Joey Roszkowski
Date:
2012-09-09 @ 13:43
The program app expects the view as the response, your code just renders 
it and is not retuning it. Change all the 'render_template(...' to 'return
render_template(...'

Should solve your problems, good luck! 

- Joe Roszkowski

On Sep 9, 2012, at 4:43 AM, jaudat hussain <sjh.jaudat@gmail.com> wrote:

> Hi, i recently decided to learn flask and mongodb using mongoengine, but
i am having trouble with my signup page here is the code: 
> 
> @user.route('/signup/', methods=['GET', 'POST'])
> def signup():
>     if request.method == "POST":
>         if request.form['password'] == request.form['verify']:
>             new = Profile(email=request.form['email'], 
password=request.form['password'])
>             try: new.save()
>             except Profile.NotUniqueError:
>                 render_template('signup.html', eerror="Email is already 
taken", verror="", perror="")
>             except ValidationError as e:
>                 render_template('signup.html', eerror="Email is of 
incorrect format", verror="", perror="")
>             session['logged_in'] = True
>             flash('You were logged in')
>             return redirect(url_for('welcome'))
>         else: render_template('signup.html', verror="Passwords do not 
match", eerror="", perror="")
>     else: render_template('signup.html', verror="",perror="",eerror="")
> 
> for some reason i keep getting the following:
> ValueError: View function did not return a response
> 
> I am confused, any help will be appreciated.