librelist archives

« back to archive

My register_blueprint functions got 404 error

My register_blueprint functions got 404 error

From:
邓超
Date:
2013-04-28 @ 07:24
Hi all,
  I wrote 2 modules like django app, and register them with blueprint, but
I got 404 error when open the root url. below is the function how I
register the module with blueprint:

    def register_blueprints(app):
        from user.views import user
        from profile.views import profile

        app.register_blueprint(user, url_prefix = '/')
        #app.register_blueprint(profile, url_prefix='/myprofile')

After I comment the second modules' registration, I can open the root url
with no error.
Does anyone met this error before? And how to solve it?

-- 
Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
薛 鹏飞
Date:
2013-05-02 @ 03:16
how do you implement your blueprints in views?  

check your url route in your views, maybe you can find something there.

--
Sincerely,
Pengfei Xue
https://life-map.rhcloud.com

在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:

> Hi all,
>   I wrote 2 modules like django app, and register them with blueprint, 
but I got 404 error when open the root url. below is the function how I 
register the module with blueprint:
> 
>     def register_blueprints(app):
>         from user.views import user
>         from profile.views import profile
>     
>         app.register_blueprint(user, url_prefix = '/')
>         #app.register_blueprint(profile, url_prefix='/myprofile')
> 
> After I comment the second modules' registration, I can open the root 
url with no error.
> Does anyone met this error before? And how to solve it?
> 
> -- 
> Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
邓超
Date:
2013-05-02 @ 12:58
This is the user's views:

user_bp = Blueprint('user', __name__, template_folder = 'templates')

@user_bp.route('/')
def index():
    try:
        form = LoginForm()

        return render_template('index.html', form = form)
    except TemplateNotFound:
        abort(404)

and this is profile's views:

profile_bp = Blueprint('profile', __name__, template_folder = 'templates')

@profile_bp.route('/myprofile')
@login_required
def view():
    try:
        form = BasicInfoForm()

        return render_template('index.html', form = form)
    except TemplateNotFound:
        abort(404)

Have you found anything wrong?


2013/5/2 薛 鹏飞 <pengphy@gmail.com>

> how do you implement your blueprints in views?
>
> check your url route in your views, maybe you can find something there.
>
> --
> Sincerely,
> Pengfei Xue
> https://life-map.rhcloud.com
>
> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>
> Hi all,
>   I wrote 2 modules like django app, and register them with blueprint, but
> I got 404 error when open the root url. below is the function how I
> register the module with blueprint:
>
>     def register_blueprints(app):
>         from user.views import user
>         from profile.views import profile
>
>         app.register_blueprint(user, url_prefix = '/')
>         #app.register_blueprint(profile, url_prefix='/myprofile')
>
> After I comment the second modules' registration, I can open the root url
> with no error.
> Does anyone met this error before? And how to solve it?
>
> --
> Deng Chao
>
>
>


-- 
Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
薛 鹏飞
Date:
2013-05-02 @ 14:57
i think the code is fine

please provide the error log when accessing the root url

--
Sincerely,
Pengfei Xue
https://life-map.rhcloud.com

在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:

> This is the user's views:
> 
> user_bp = Blueprint('user', __name__, template_folder = 'templates')
> 
> @user_bp.route('/')
> def index():
>     try:
>         form = LoginForm()
>         
>         return render_template('index.html', form = form)
>     except TemplateNotFound:
>         abort(404)
> 
> and this is profile's views:
> 
> profile_bp = Blueprint('profile', __name__, template_folder = 'templates')
> 
> @profile_bp.route('/myprofile')
> @login_required
> def view():
>     try:
>         form = BasicInfoForm()
>         
>         return render_template('index.html', form = form)
>     except TemplateNotFound:
>         abort(404)
> 
> Have you found anything wrong?
> 
> 
> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
> how do you implement your blueprints in views?  
> 
> check your url route in your views, maybe you can find something there.
> 
> --
> Sincerely,
> Pengfei Xue
> https://life-map.rhcloud.com
> 
> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
> 
>> Hi all,
>>   I wrote 2 modules like django app, and register them with blueprint, 
but I got 404 error when open the root url. below is the function how I 
register the module with blueprint:
>> 
>>     def register_blueprints(app):
>>         from user.views import user
>>         from profile.views import profile
>>     
>>         app.register_blueprint(user, url_prefix = '/')
>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>> 
>> After I comment the second modules' registration, I can open the root 
url with no error.
>> Does anyone met this error before? And how to solve it?
>> 
>> -- 
>> Deng Chao
> 
> 
> 
> 
> -- 
> Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
邓超
Date:
2013-05-03 @ 02:02
I checked the printed message in the terminal, it just said 404


2013/5/2 薛 鹏飞 <pengphy@gmail.com>

> i think the code is fine
>
> please provide the error log when accessing the root url
>
> --
> Sincerely,
> Pengfei Xue
> https://life-map.rhcloud.com
>
> 在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:
>
> This is the user's views:
>
> user_bp = Blueprint('user', __name__, template_folder = 'templates')
>
> @user_bp.route('/')
> def index():
>     try:
>         form = LoginForm()
>
>         return render_template('index.html', form = form)
>     except TemplateNotFound:
>         abort(404)
>
> and this is profile's views:
>
> profile_bp = Blueprint('profile', __name__, template_folder = 'templates')
>
> @profile_bp.route('/myprofile')
> @login_required
> def view():
>     try:
>         form = BasicInfoForm()
>
>         return render_template('index.html', form = form)
>     except TemplateNotFound:
>         abort(404)
>
> Have you found anything wrong?
>
>
> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>
>> how do you implement your blueprints in views?
>>
>> check your url route in your views, maybe you can find something there.
>>
>>  --
>> Sincerely,
>> Pengfei Xue
>> https://life-map.rhcloud.com
>>
>> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>>
>> Hi all,
>>   I wrote 2 modules like django app, and register them with blueprint,
>> but I got 404 error when open the root url. below is the function how I
>> register the module with blueprint:
>>
>>     def register_blueprints(app):
>>         from user.views import user
>>         from profile.views import profile
>>
>>         app.register_blueprint(user, url_prefix = '/')
>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>>
>> After I comment the second modules' registration, I can open the root url
>> with no error.
>> Does anyone met this error before? And how to solve it?
>>
>> --
>> Deng Chao
>>
>>
>>
>
>
> --
> Deng Chao
>
>
>


-- 
Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
薛 鹏飞
Date:
2013-05-03 @ 03:31
you can print your url map after registered those two blueprints

and add some debug info into the related views, this way you must can find
something useful

--
Sincerely,
Pengfei Xue
https://life-map.rhcloud.com

在 2013-5-3,上午10:02,邓超 <knifewolf@gmail.com> 写道:

> I checked the printed message in the terminal, it just said 404
> 
> 
> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
> i think the code is fine
> 
> please provide the error log when accessing the root url
> 
> --
> Sincerely,
> Pengfei Xue
> https://life-map.rhcloud.com
> 
> 在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:
> 
>> This is the user's views:
>> 
>> user_bp = Blueprint('user', __name__, template_folder = 'templates')
>> 
>> @user_bp.route('/')
>> def index():
>>     try:
>>         form = LoginForm()
>>         
>>         return render_template('index.html', form = form)
>>     except TemplateNotFound:
>>         abort(404)
>> 
>> and this is profile's views:
>> 
>> profile_bp = Blueprint('profile', __name__, template_folder = 'templates')
>> 
>> @profile_bp.route('/myprofile')
>> @login_required
>> def view():
>>     try:
>>         form = BasicInfoForm()
>>         
>>         return render_template('index.html', form = form)
>>     except TemplateNotFound:
>>         abort(404)
>> 
>> Have you found anything wrong?
>> 
>> 
>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>> how do you implement your blueprints in views?  
>> 
>> check your url route in your views, maybe you can find something there.
>> 
>> --
>> Sincerely,
>> Pengfei Xue
>> https://life-map.rhcloud.com
>> 
>> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>> 
>>> Hi all,
>>>   I wrote 2 modules like django app, and register them with blueprint,
but I got 404 error when open the root url. below is the function how I 
register the module with blueprint:
>>> 
>>>     def register_blueprints(app):
>>>         from user.views import user
>>>         from profile.views import profile
>>>     
>>>         app.register_blueprint(user, url_prefix = '/')
>>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>>> 
>>> After I comment the second modules' registration, I can open the root 
url with no error.
>>> Does anyone met this error before? And how to solve it?
>>> 
>>> -- 
>>> Deng Chao
>> 
>> 
>> 
>> 
>> -- 
>> Deng Chao
> 
> 
> 
> 
> -- 
> Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
Alex Ogier
Date:
2013-05-03 @ 04:45
It's worth pointing out that your view functions include a try-except block
that catches TemplateNotFound exceptions and throws them away by calling
abort(404).

If you are using a template that you know should exist, that error should
never occur. So I recommend removing the try-except block. That way the
error will be caught by flask's standard error routines. If DEBUG is on
then you will see a traceback in the browser. If not it will at least show
up in the logs.
On May 2, 2013 11:32 PM, "薛 鹏飞" <pengphy@gmail.com> wrote:

> you can print your url map after registered those two blueprints
>
> and add some debug info into the related views, this way you must can find
> something useful
>
> --
> Sincerely,
> Pengfei Xue
> https://life-map.rhcloud.com
>
> 在 2013-5-3,上午10:02,邓超 <knifewolf@gmail.com> 写道:
>
> I checked the printed message in the terminal, it just said 404
>
>
> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>
>> i think the code is fine
>>
>> please provide the error log when accessing the root url
>>
>>  --
>> Sincerely,
>> Pengfei Xue
>> https://life-map.rhcloud.com
>>
>> 在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:
>>
>> This is the user's views:
>>
>> user_bp = Blueprint('user', __name__, template_folder = 'templates')
>>
>> @user_bp.route('/')
>> def index():
>>     try:
>>         form = LoginForm()
>>
>>         return render_template('index.html', form = form)
>>     except TemplateNotFound:
>>         abort(404)
>>
>> and this is profile's views:
>>
>> profile_bp = Blueprint('profile', __name__, template_folder = 'templates')
>>
>> @profile_bp.route('/myprofile')
>> @login_required
>> def view():
>>     try:
>>         form = BasicInfoForm()
>>
>>         return render_template('index.html', form = form)
>>     except TemplateNotFound:
>>         abort(404)
>>
>> Have you found anything wrong?
>>
>>
>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>>
>>> how do you implement your blueprints in views?
>>>
>>> check your url route in your views, maybe you can find something there.
>>>
>>>  --
>>> Sincerely,
>>> Pengfei Xue
>>> https://life-map.rhcloud.com
>>>
>>> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>>>
>>> Hi all,
>>>   I wrote 2 modules like django app, and register them with blueprint,
>>> but I got 404 error when open the root url. below is the function how I
>>> register the module with blueprint:
>>>
>>>     def register_blueprints(app):
>>>         from user.views import user
>>>         from profile.views import profile
>>>
>>>         app.register_blueprint(user, url_prefix = '/')
>>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>>>
>>> After I comment the second modules' registration, I can open the root
>>> url with no error.
>>> Does anyone met this error before? And how to solve it?
>>>
>>> --
>>> Deng Chao
>>>
>>>
>>>
>>
>>
>> --
>> Deng Chao
>>
>>
>>
>
>
> --
> Deng Chao
>
>
>

Re: [flask] My register_blueprint functions got 404 error

From:
邓超
Date:
2013-05-06 @ 01:10
OK, thanks. I'll try it tonight.


2013/5/3 Alex Ogier <alex.ogier@gmail.com>

> It's worth pointing out that your view functions include a try-except
> block that catches TemplateNotFound exceptions and throws them away by
> calling abort(404).
>
> If you are using a template that you know should exist, that error should
> never occur. So I recommend removing the try-except block. That way the
> error will be caught by flask's standard error routines. If DEBUG is on
> then you will see a traceback in the browser. If not it will at least show
> up in the logs.
> On May 2, 2013 11:32 PM, "薛 鹏飞" <pengphy@gmail.com> wrote:
>
>> you can print your url map after registered those two blueprints
>>
>> and add some debug info into the related views, this way you must can
>> find something useful
>>
>>  --
>> Sincerely,
>> Pengfei Xue
>> https://life-map.rhcloud.com
>>
>> 在 2013-5-3,上午10:02,邓超 <knifewolf@gmail.com> 写道:
>>
>> I checked the printed message in the terminal, it just said 404
>>
>>
>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>>
>>> i think the code is fine
>>>
>>> please provide the error log when accessing the root url
>>>
>>>  --
>>> Sincerely,
>>> Pengfei Xue
>>> https://life-map.rhcloud.com
>>>
>>> 在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:
>>>
>>> This is the user's views:
>>>
>>> user_bp = Blueprint('user', __name__, template_folder = 'templates')
>>>
>>> @user_bp.route('/')
>>> def index():
>>>     try:
>>>         form = LoginForm()
>>>
>>>         return render_template('index.html', form = form)
>>>     except TemplateNotFound:
>>>         abort(404)
>>>
>>> and this is profile's views:
>>>
>>> profile_bp = Blueprint('profile', __name__, template_folder =
>>> 'templates')
>>>
>>> @profile_bp.route('/myprofile')
>>> @login_required
>>> def view():
>>>     try:
>>>         form = BasicInfoForm()
>>>
>>>         return render_template('index.html', form = form)
>>>     except TemplateNotFound:
>>>         abort(404)
>>>
>>> Have you found anything wrong?
>>>
>>>
>>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>>>
>>>> how do you implement your blueprints in views?
>>>>
>>>> check your url route in your views, maybe you can find something there.
>>>>
>>>>  --
>>>> Sincerely,
>>>> Pengfei Xue
>>>> https://life-map.rhcloud.com
>>>>
>>>> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>>>>
>>>> Hi all,
>>>>   I wrote 2 modules like django app, and register them with blueprint,
>>>> but I got 404 error when open the root url. below is the function how I
>>>> register the module with blueprint:
>>>>
>>>>     def register_blueprints(app):
>>>>         from user.views import user
>>>>         from profile.views import profile
>>>>
>>>>         app.register_blueprint(user, url_prefix = '/')
>>>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>>>>
>>>> After I comment the second modules' registration, I can open the root
>>>> url with no error.
>>>> Does anyone met this error before? And how to solve it?
>>>>
>>>> --
>>>> Deng Chao
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Deng Chao
>>>
>>>
>>>
>>
>>
>> --
>> Deng Chao
>>
>>
>>


-- 
Deng Chao

Re: [flask] My register_blueprint functions got 404 error

From:
邓超
Date:
2013-05-06 @ 12:40
Thank you very much! I solved the problem. the reason is I set the same
name for the template file. in the 'User' module, there is an 'index.html'
file, and in the 'Profile' module, there is an 'index.html' file too. so
the program can not find the correct template file.


2013/5/6 邓超 <knifewolf@gmail.com>

> OK, thanks. I'll try it tonight.
>
>
> 2013/5/3 Alex Ogier <alex.ogier@gmail.com>
>
>> It's worth pointing out that your view functions include a try-except
>> block that catches TemplateNotFound exceptions and throws them away by
>> calling abort(404).
>>
>> If you are using a template that you know should exist, that error should
>> never occur. So I recommend removing the try-except block. That way the
>> error will be caught by flask's standard error routines. If DEBUG is on
>> then you will see a traceback in the browser. If not it will at least show
>> up in the logs.
>>  On May 2, 2013 11:32 PM, "薛 鹏飞" <pengphy@gmail.com> wrote:
>>
>>> you can print your url map after registered those two blueprints
>>>
>>> and add some debug info into the related views, this way you must can
>>> find something useful
>>>
>>>  --
>>> Sincerely,
>>> Pengfei Xue
>>> https://life-map.rhcloud.com
>>>
>>> 在 2013-5-3,上午10:02,邓超 <knifewolf@gmail.com> 写道:
>>>
>>> I checked the printed message in the terminal, it just said 404
>>>
>>>
>>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>>>
>>>> i think the code is fine
>>>>
>>>> please provide the error log when accessing the root url
>>>>
>>>>  --
>>>> Sincerely,
>>>> Pengfei Xue
>>>> https://life-map.rhcloud.com
>>>>
>>>> 在 2013-5-2,下午8:58,"邓超" <knifewolf@gmail.com> 写道:
>>>>
>>>> This is the user's views:
>>>>
>>>> user_bp = Blueprint('user', __name__, template_folder = 'templates')
>>>>
>>>> @user_bp.route('/')
>>>> def index():
>>>>     try:
>>>>         form = LoginForm()
>>>>
>>>>         return render_template('index.html', form = form)
>>>>     except TemplateNotFound:
>>>>         abort(404)
>>>>
>>>> and this is profile's views:
>>>>
>>>> profile_bp = Blueprint('profile', __name__, template_folder =
>>>> 'templates')
>>>>
>>>> @profile_bp.route('/myprofile')
>>>> @login_required
>>>> def view():
>>>>     try:
>>>>         form = BasicInfoForm()
>>>>
>>>>         return render_template('index.html', form = form)
>>>>     except TemplateNotFound:
>>>>         abort(404)
>>>>
>>>> Have you found anything wrong?
>>>>
>>>>
>>>> 2013/5/2 薛 鹏飞 <pengphy@gmail.com>
>>>>
>>>>> how do you implement your blueprints in views?
>>>>>
>>>>> check your url route in your views, maybe you can find something there.
>>>>>
>>>>>  --
>>>>> Sincerely,
>>>>> Pengfei Xue
>>>>> https://life-map.rhcloud.com
>>>>>
>>>>> 在 2013-4-28,下午3:24,邓超 <knifewolf@gmail.com> 写道:
>>>>>
>>>>> Hi all,
>>>>>   I wrote 2 modules like django app, and register them with blueprint,
>>>>> but I got 404 error when open the root url. below is the function how I
>>>>> register the module with blueprint:
>>>>>
>>>>>     def register_blueprints(app):
>>>>>         from user.views import user
>>>>>         from profile.views import profile
>>>>>
>>>>>         app.register_blueprint(user, url_prefix = '/')
>>>>>         #app.register_blueprint(profile, url_prefix='/myprofile')
>>>>>
>>>>> After I comment the second modules' registration, I can open the root
>>>>> url with no error.
>>>>> Does anyone met this error before? And how to solve it?
>>>>>
>>>>> --
>>>>> Deng Chao
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Deng Chao
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Deng Chao
>>>
>>>
>>>
>
>
> --
> Deng Chao
>



-- 
Deng Chao