librelist archives

« back to archive

Fwd: a small problem that i need to know how to solve in flask

Fwd: a small problem that i need to know how to solve in flask

From:
jeff uzodinma
Date:
2012-04-05 @ 14:56
---------- Forwarded message ----------
From: jeff uzodinma <jeffdico@gmail.com>
Date: Thu, Apr 5, 2012 at 3:52 PM
Subject: a small problem that i need to know how to solve in flask
To: meta@librelist.com


my name is jeff and am currently working on a site and am using flask,
flask wtforms, jinja2 templates etc

please see the following code snippets on flask.
from flask ....
@app.route('/newcomment/<data>',methods=['GET','POST'])
def comment(data=None):
        if method.request == "POST":
                    cheq *= data
                   return render_template (''checker_template.html" ,
cheq=cheq")

@app.route('/*facto*/<data>',methods=['GET','POST'])
def comment(data=None):
       return redirect('/newcomment)

the problem is that i want to be able to redirect to the view (comment) but
am getting a 404 error page request.
please i need help here, thanks in advance.

Re: Fwd: a small problem that i need to know how to solve in flask

From:
Peter Wang
Date:
2012-04-05 @ 15:58
On Apr 5, 2012, at 9:56 AM, jeff uzodinma wrote:

> ---------- Forwarded message ----------
> From: jeff uzodinma <jeffdico@gmail.com>
> Date: Thu, Apr 5, 2012 at 3:52 PM
> Subject: a small problem that i need to know how to solve in flask
> To: meta@librelist.com
> 
> my name is jeff and am currently working on a site and am using flask, 
flask wtforms, jinja2 templates etc
> please see the following code snippets on flask.
> from flask ....
> @app.route('/newcomment/<data>',methods=['GET','POST'])
> def comment(data=None):
>         if method.request == "POST":  
>                     cheq *= data 
>                    return render_template (''checker_template.html" , 
cheq=cheq")
> 
> @app.route('/facto/<data>',methods=['GET','POST'])
> def comment(data=None):
>        return redirect('/newcomment)
> 
> the problem is that i want to be able to redirect to the view (comment) 
but am getting a 404 error page request.
> please i need help here, thanks in advance.

1. Don't name both handler functions the same ("comment()").  This may or 
may not be the source of your troubles (depends on the implementation of 
routing inside Flask), but it's bad practice either way.

2. You should add a route rule above the first comment: @app.route('/newcomment/')
Just providing a default parameter to the Python function doesn't change 
how Flask tries to pattern match for the URL '/newcomment/<data>'.


-Peter

Re: Fwd: a small problem that i need to know how to solve in flask

From:
jeff uzodinma
Date:
2012-04-05 @ 17:54
i tried just that and am still getting the same 404 error page request.
then i tried using this:
from flask ....
@app.route('/newcomment/<data>',methods=['GET','POST'])
def comment(data=None):
        if method.request == "POST":
                    cheq *= data
                    #appropriate code lines

                 return render_template (''checker_template.html" ,
cheq=cheq")

#-------------------------------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------------------------------


@app.route('/*facto*/<data>',methods=['GET','POST'])
def promatrix(data):

       #appropriate code lines

       return redirect('url_for('comment'))


#-------------------------------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------------------------------


And i get a BuildError: (' comment', {}, None) from the function. i know
the problem is not from the whole code but from the 'return redirect()
attribute'  i just don't know what exactly is wrong. Am actually using a
blueprint to run it so it is represented as :


from flask ....
app = Blueprint('commentzone', __name__, url_prefix='/commentzone')


@app.route('/newcomment/<data>,methods=['GET','POST'])
def comment(data=None):
        if method.request == "POST":
                    cheq *= data
                    #appropriate code lines
                   return render_template (''checker_template.html" ,
cheq=cheq")


#-------------------------------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------------------------------
@app.route('/*facto*/<data>',methods=['GET','POST'])
def promatrix(data=None):
       #appropriate code lines
       return redirect('url_for('commentzone.comment'))



#-------------------------------------------------------------------------------------------------------------------------

#-------------------------------------------------------------------------------------------------------------------------


although what's above is the sane with the second code lines, the problems
still remains the same. i appreciate  your help reply in advance, thanks
 my name is Jeff by the way


On Thu, Apr 5, 2012 at 4:58 PM, Peter Wang <pwang@continuum.io> wrote:

> On Apr 5, 2012, at 9:56 AM, jeff uzodinma wrote:
>
> ---------- Forwarded message ----------
> From: jeff uzodinma <jeffdico@gmail.com>
> Date: Thu, Apr 5, 2012 at 3:52 PM
> Subject: a small problem that i need to know how to solve in flask
> To: meta@librelist.com
>
> my name is jeff and am currently working on a site and am using flask,
> flask wtforms, jinja2 templates etc
> please see the following code snippets on flask.
> from flask ....
> @app.route('/newcomment/<data>',methods=['GET','POST'])
> def comment(data=None):
>         if method.request == "POST":
>                     cheq *= data
>                    return render_template (''checker_template.html" ,
> cheq=cheq")
>
> @app.route('/*facto*/<data>',methods=['GET','POST'])
> def (data=None):
>        return redirect('/newcomment)
>
> the problem is that i want to be able to redirect to the view (comment)
> but am getting a 404 error page request.
> please i need help here, thanks in advance.
>
>
> 1. Don't name both handler functions the same ("comment()").  This may or
> may not be the source of your troubles (depends on the implementation of
> routing inside Flask), but it's bad practice either way.
>
> 2. You should add a route rule above the first
> comment: @app.route('/newcomment/')
> Just providing a default parameter to the Python function doesn't change
> how Flask tries to pattern match for the URL '/newcomment/<data>'.
>
>
> -Peter
>
>