librelist archives

« back to archive

Blueprint only showing the rool url

Blueprint only showing the rool url

From:
Philippe Ndiaye
Date:
2013-07-16 @ 20:08
Hi !

I am developing a Flask application using Blueprints and i've have a little
problem with it.
*First*: my project tree

Project/
    __init__.py
    apps/
        __init__.py
        admin/
            templates/
                (some blueprint specific templates)
            __init__.py
            account.py
    models/
            __init__.py
    static/
        images/
        stylesheets/
        javascripts/
    templates/
         (some generic templates)
    config.py


*Second*: as you have probably guess, my apps/ directory contains a
blueprint named admin. Here is the code in apps/admin/__init__.py:

from flask import Blueprint, render_template

admin = Blueprint('admin', __name__, template_folder='templates')

@admin.route('/')
def admin_index():
    return render_template('index.html.jinja2')

and i have another routes in apps/admin/account.py:

from . import admin
@admin.route('login/')
def login():
    return "Login Page"

In Project/__init__.py i register the blueprint that way:

from flask import Flask
from . import config

app = Flask(__name__)
app.config.from_object(config.DevelopmentConfig)

# Register blueprints and error handlers
from .apps.admin import admin
app.register_blueprint(admin, url_prefix='/admin')

*Third*
The problem is the following: only the localhost:5000/admin works. All the
other routes defined in admin/account.py throw a 404 NotFound and i really
not seing where the problem belongs.
I have even removed my system Flask and reinstalled Flask in my virtualenv
to see if it could solve the problem but nothing.

So, if you have any idea, help me please.
Thanks, by advance.

-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Blueprint only showing the rool url

From:
Jaime Wyant
Date:
2013-07-16 @ 20:59
I think you need to change this

@admin.route('login')

to

@admin.route('/login')




On Tue, Jul 16, 2013 at 3:08 PM, Philippe NDIAYE <phndiaye@gmail.com> wrote:

> Hi !
>
> I am developing a Flask application using Blueprints and i've have a
> little problem with it.
> *First*: my project tree
>
> Project/
>     __init__.py
>     apps/
>         __init__.py
>         admin/
>             templates/
>                 (some blueprint specific templates)
>             __init__.py
>             account.py
>     models/
>             __init__.py
>     static/
>         images/
>         stylesheets/
>         javascripts/
>     templates/
>          (some generic templates)
>     config.py
>
>
> *Second*: as you have probably guess, my apps/ directory contains a
> blueprint named admin. Here is the code in apps/admin/__init__.py:
>
> from flask import Blueprint, render_template
>
> admin = Blueprint('admin', __name__, template_folder='templates')
>
> @admin.route('/')
> def admin_index():
>     return render_template('index.html.jinja2')
>
> and i have another routes in apps/admin/account.py:
>
> from . import admin
> @admin.route('login/')
> def login():
>     return "Login Page"
>
> In Project/__init__.py i register the blueprint that way:
>
> from flask import Flask
> from . import config
>
> app = Flask(__name__)
> app.config.from_object(config.DevelopmentConfig)
>
> # Register blueprints and error handlers
> from .apps.admin import admin
> app.register_blueprint(admin, url_prefix='/admin')
>
> *Third*
> The problem is the following: only the localhost:5000/admin works. All the
> other routes defined in admin/account.py throw a 404 NotFound and i really
> not seing where the problem belongs.
> I have even removed my system Flask and reinstalled Flask in my virtualenv
> to see if it could solve the problem but nothing.
>
> So, if you have any idea, help me please.
> Thanks, by advance.
>
> --
> Regards,
> *
> *
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux Sysadmin  & Python programmer
>



-- 
"Government does not solve problems; it subsidizes them."
Ronald Reagan

Re: [flask] Blueprint only showing the rool url

From:
Philippe Ndiaye
Date:
2013-07-16 @ 21:16
I still have the same error: the route is not Found


On Tue, Jul 16, 2013 at 10:59 PM, Jaime Wyant <programmer.py@gmail.com>wrote:

> I think you need to change this
>
> @admin.route('login')
>
> to
>
> @admin.route('/login')
>
>
>
>
> On Tue, Jul 16, 2013 at 3:08 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>
>> Hi !
>>
>> I am developing a Flask application using Blueprints and i've have a
>> little problem with it.
>> *First*: my project tree
>>
>> Project/
>>     __init__.py
>>     apps/
>>         __init__.py
>>         admin/
>>             templates/
>>                 (some blueprint specific templates)
>>             __init__.py
>>             account.py
>>     models/
>>             __init__.py
>>     static/
>>         images/
>>         stylesheets/
>>         javascripts/
>>     templates/
>>          (some generic templates)
>>     config.py
>>
>>
>> *Second*: as you have probably guess, my apps/ directory contains a
>> blueprint named admin. Here is the code in apps/admin/__init__.py:
>>
>> from flask import Blueprint, render_template
>>
>> admin = Blueprint('admin', __name__, template_folder='templates')
>>
>> @admin.route('/')
>> def admin_index():
>>     return render_template('index.html.jinja2')
>>
>> and i have another routes in apps/admin/account.py:
>>
>> from . import admin
>> @admin.route('login/')
>> def login():
>>     return "Login Page"
>>
>> In Project/__init__.py i register the blueprint that way:
>>
>> from flask import Flask
>> from . import config
>>
>> app = Flask(__name__)
>> app.config.from_object(config.DevelopmentConfig)
>>
>> # Register blueprints and error handlers
>> from .apps.admin import admin
>> app.register_blueprint(admin, url_prefix='/admin')
>>
>> *Third*
>> The problem is the following: only the localhost:5000/admin works. All
>> the other routes defined in admin/account.py throw a 404 NotFound and i
>> really not seing where the problem belongs.
>> I have even removed my system Flask and reinstalled Flask in my
>> virtualenv to see if it could solve the problem but nothing.
>>
>> So, if you have any idea, help me please.
>> Thanks, by advance.
>>
>> --
>> Regards,
>> *
>> *
>> *Philippe Thécou NDIAYE*
>> IT Student @ SUPINFO Lyon
>> Linux Sysadmin  & Python programmer
>>
>
>
>
> --
> "Government does not solve problems; it subsidizes them."
> Ronald Reagan
>



-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer

Re: [flask] Blueprint only showing the rool url

From:
Jaime Wyant
Date:
2013-07-16 @ 23:28
When I have trouble tracking down route problems I use url_for to determine
what the "real" route is.  Add this to the bottom of the app and check the
output.

from flask import url_for
print 'URL route', url_for('admin.login')

That should give you the real route.  If that gives you a BuildError then
print out the url map like so:

print app.url_map

I tend to like working inside the shell, well the IPython shell.  This
script (you'll need to modify it to work with your application) with
IPython will let you do stuff like call url_for directly:


## Shell for flask apps.
import IPython
# Change the next three lines to use your app...
from ssflask.config import DevelopmentConfig
from ssflask import make_app
app = make_app(DevelopmentConfig)

ctx = app.test_request_context()
ctx.push()

# Do other stuff, like import database modules.  All variables
# here will be available inside the shell.
IPython.embed()





On Tue, Jul 16, 2013 at 4:16 PM, Philippe NDIAYE <phndiaye@gmail.com> wrote:

> I still have the same error: the route is not Found
>
>
> On Tue, Jul 16, 2013 at 10:59 PM, Jaime Wyant <programmer.py@gmail.com>wrote:
>
>> I think you need to change this
>>
>> @admin.route('login')
>>
>> to
>>
>> @admin.route('/login')
>>
>>
>>
>>
>> On Tue, Jul 16, 2013 at 3:08 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>>
>>> Hi !
>>>
>>> I am developing a Flask application using Blueprints and i've have a
>>> little problem with it.
>>> *First*: my project tree
>>>
>>> Project/
>>>     __init__.py
>>>     apps/
>>>         __init__.py
>>>         admin/
>>>             templates/
>>>                 (some blueprint specific templates)
>>>             __init__.py
>>>             account.py
>>>     models/
>>>             __init__.py
>>>     static/
>>>         images/
>>>         stylesheets/
>>>         javascripts/
>>>     templates/
>>>          (some generic templates)
>>>     config.py
>>>
>>>
>>> *Second*: as you have probably guess, my apps/ directory contains a
>>> blueprint named admin. Here is the code in apps/admin/__init__.py:
>>>
>>> from flask import Blueprint, render_template
>>>
>>> admin = Blueprint('admin', __name__, template_folder='templates')
>>>
>>> @admin.route('/')
>>> def admin_index():
>>>     return render_template('index.html.jinja2')
>>>
>>> and i have another routes in apps/admin/account.py:
>>>
>>> from . import admin
>>> @admin.route('login/')
>>> def login():
>>>     return "Login Page"
>>>
>>> In Project/__init__.py i register the blueprint that way:
>>>
>>> from flask import Flask
>>> from . import config
>>>
>>> app = Flask(__name__)
>>> app.config.from_object(config.DevelopmentConfig)
>>>
>>> # Register blueprints and error handlers
>>> from .apps.admin import admin
>>> app.register_blueprint(admin, url_prefix='/admin')
>>>
>>> *Third*
>>> The problem is the following: only the localhost:5000/admin works. All
>>> the other routes defined in admin/account.py throw a 404 NotFound and i
>>> really not seing where the problem belongs.
>>> I have even removed my system Flask and reinstalled Flask in my
>>> virtualenv to see if it could solve the problem but nothing.
>>>
>>> So, if you have any idea, help me please.
>>> Thanks, by advance.
>>>
>>> --
>>> Regards,
>>> *
>>> *
>>> *Philippe Thécou NDIAYE*
>>> IT Student @ SUPINFO Lyon
>>> Linux Sysadmin  & Python programmer
>>>
>>
>>
>>
>> --
>> "Government does not solve problems; it subsidizes them."
>> Ronald Reagan
>>
>
>
>
> --
> Regards,
> *
> *
> *Philippe Thécou NDIAYE*
> IT Student @ SUPINFO Lyon
> Linux Sysadmin  & Python programmer
>



-- 
"Government does not solve problems; it subsidizes them."
Ronald Reagan

Re: [flask] Blueprint only showing the rool url

From:
Kates Gasis
Date:
2013-07-17 @ 01:15
Try
`admin = Blueprint('admin', __name__, template_folder='templates',
url_prefix="/admin")`



On Wed, Jul 17, 2013 at 7:28 AM, Jaime Wyant <programmer.py@gmail.com>wrote:

> When I have trouble tracking down route problems I use url_for to
> determine what the "real" route is.  Add this to the bottom of the app and
> check the output.
>
> from flask import url_for
> print 'URL route', url_for('admin.login')
>
> That should give you the real route.  If that gives you a BuildError then
> print out the url map like so:
>
> print app.url_map
>
> I tend to like working inside the shell, well the IPython shell.  This
> script (you'll need to modify it to work with your application) with
> IPython will let you do stuff like call url_for directly:
>
>
> ## Shell for flask apps.
> import IPython
> # Change the next three lines to use your app...
> from ssflask.config import DevelopmentConfig
> from ssflask import make_app
> app = make_app(DevelopmentConfig)
>
> ctx = app.test_request_context()
> ctx.push()
>
> # Do other stuff, like import database modules.  All variables
> # here will be available inside the shell.
> IPython.embed()
>
>
>
>
>
> On Tue, Jul 16, 2013 at 4:16 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>
>> I still have the same error: the route is not Found
>>
>>
>> On Tue, Jul 16, 2013 at 10:59 PM, Jaime Wyant <programmer.py@gmail.com>wrote:
>>
>>> I think you need to change this
>>>
>>> @admin.route('login')
>>>
>>> to
>>>
>>> @admin.route('/login')
>>>
>>>
>>>
>>>
>>> On Tue, Jul 16, 2013 at 3:08 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>>>
>>>> Hi !
>>>>
>>>> I am developing a Flask application using Blueprints and i've have a
>>>> little problem with it.
>>>> *First*: my project tree
>>>>
>>>> Project/
>>>>     __init__.py
>>>>     apps/
>>>>         __init__.py
>>>>         admin/
>>>>             templates/
>>>>                 (some blueprint specific templates)
>>>>             __init__.py
>>>>             account.py
>>>>     models/
>>>>             __init__.py
>>>>     static/
>>>>         images/
>>>>         stylesheets/
>>>>         javascripts/
>>>>     templates/
>>>>          (some generic templates)
>>>>     config.py
>>>>
>>>>
>>>> *Second*: as you have probably guess, my apps/ directory contains a
>>>> blueprint named admin. Here is the code in apps/admin/__init__.py:
>>>>
>>>> from flask import Blueprint, render_template
>>>>
>>>> admin = Blueprint('admin', __name__, template_folder='templates')
>>>>
>>>> @admin.route('/')
>>>> def admin_index():
>>>>     return render_template('index.html.jinja2')
>>>>
>>>> and i have another routes in apps/admin/account.py:
>>>>
>>>> from . import admin
>>>> @admin.route('login/')
>>>> def login():
>>>>     return "Login Page"
>>>>
>>>> In Project/__init__.py i register the blueprint that way:
>>>>
>>>> from flask import Flask
>>>> from . import config
>>>>
>>>> app = Flask(__name__)
>>>> app.config.from_object(config.DevelopmentConfig)
>>>>
>>>> # Register blueprints and error handlers
>>>> from .apps.admin import admin
>>>> app.register_blueprint(admin, url_prefix='/admin')
>>>>
>>>> *Third*
>>>> The problem is the following: only the localhost:5000/admin works. All
>>>> the other routes defined in admin/account.py throw a 404 NotFound and i
>>>> really not seing where the problem belongs.
>>>> I have even removed my system Flask and reinstalled Flask in my
>>>> virtualenv to see if it could solve the problem but nothing.
>>>>
>>>> So, if you have any idea, help me please.
>>>> Thanks, by advance.
>>>>
>>>> --
>>>> Regards,
>>>> *
>>>> *
>>>> *Philippe Thécou NDIAYE*
>>>> IT Student @ SUPINFO Lyon
>>>> Linux Sysadmin  & Python programmer
>>>>
>>>
>>>
>>>
>>> --
>>> "Government does not solve problems; it subsidizes them."
>>> Ronald Reagan
>>>
>>
>>
>>
>> --
>> Regards,
>> *
>> *
>> *Philippe Thécou NDIAYE*
>> IT Student @ SUPINFO Lyon
>> Linux Sysadmin  & Python programmer
>>
>
>
>
> --
> "Government does not solve problems; it subsidizes them."
> Ronald Reagan
>

Re: [flask] Blueprint only showing the rool url

From:
Philippe Ndiaye
Date:
2013-07-17 @ 06:02
I've tried this, but it doesn't work :/ Thanks.

@Jaime
First: thanks for the script, this method for working with Flask is such a
good one.
I've done an 'url_for' that gave me a BuildError on 'admin.login' and, when
i print the url_map, this url doesn't appear, just like it doens't exists.
So, i have moved the login route from the account.py file to the
__init__.pyand ... IT WORKED !!

That permitted me to deduce that maybe it was an import problem (even if i
was sure that wherever you import your blueprint object and build a route
with it, it will be updated -> I was probably wrong).

So, i juste imported the account module into my admin/__init__.py and the
urls in it are correctly discovered.

Thanks for your help (and the amazing IPython method)


On Wed, Jul 17, 2013 at 3:15 AM, Kates Gasis <katesgasis@gmail.com> wrote:

> Try
> `admin = Blueprint('admin', __name__, template_folder='templates',
> url_prefix="/admin")`
>
>
>
> On Wed, Jul 17, 2013 at 7:28 AM, Jaime Wyant <programmer.py@gmail.com>wrote:
>
>> When I have trouble tracking down route problems I use url_for to
>> determine what the "real" route is.  Add this to the bottom of the app and
>> check the output.
>>
>> from flask import url_for
>> print 'URL route', url_for('admin.login')
>>
>> That should give you the real route.  If that gives you a BuildError then
>> print out the url map like so:
>>
>> print app.url_map
>>
>> I tend to like working inside the shell, well the IPython shell.  This
>> script (you'll need to modify it to work with your application) with
>> IPython will let you do stuff like call url_for directly:
>>
>>
>> ## Shell for flask apps.
>> import IPython
>> # Change the next three lines to use your app...
>> from ssflask.config import DevelopmentConfig
>> from ssflask import make_app
>> app = make_app(DevelopmentConfig)
>>
>> ctx = app.test_request_context()
>> ctx.push()
>>
>> # Do other stuff, like import database modules.  All variables
>> # here will be available inside the shell.
>> IPython.embed()
>>
>>
>>
>>
>>
>> On Tue, Jul 16, 2013 at 4:16 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>>
>>> I still have the same error: the route is not Found
>>>
>>>
>>> On Tue, Jul 16, 2013 at 10:59 PM, Jaime Wyant <programmer.py@gmail.com>wrote:
>>>
>>>> I think you need to change this
>>>>
>>>> @admin.route('login')
>>>>
>>>> to
>>>>
>>>> @admin.route('/login')
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Jul 16, 2013 at 3:08 PM, Philippe NDIAYE <phndiaye@gmail.com>wrote:
>>>>
>>>>> Hi !
>>>>>
>>>>> I am developing a Flask application using Blueprints and i've have a
>>>>> little problem with it.
>>>>> *First*: my project tree
>>>>>
>>>>> Project/
>>>>>     __init__.py
>>>>>     apps/
>>>>>         __init__.py
>>>>>         admin/
>>>>>             templates/
>>>>>                 (some blueprint specific templates)
>>>>>             __init__.py
>>>>>             account.py
>>>>>     models/
>>>>>             __init__.py
>>>>>     static/
>>>>>         images/
>>>>>         stylesheets/
>>>>>         javascripts/
>>>>>     templates/
>>>>>          (some generic templates)
>>>>>     config.py
>>>>>
>>>>>
>>>>> *Second*: as you have probably guess, my apps/ directory contains a
>>>>> blueprint named admin. Here is the code in apps/admin/__init__.py:
>>>>>
>>>>> from flask import Blueprint, render_template
>>>>>
>>>>> admin = Blueprint('admin', __name__, template_folder='templates')
>>>>>
>>>>> @admin.route('/')
>>>>> def admin_index():
>>>>>     return render_template('index.html.jinja2')
>>>>>
>>>>> and i have another routes in apps/admin/account.py:
>>>>>
>>>>> from . import admin
>>>>> @admin.route('login/')
>>>>> def login():
>>>>>     return "Login Page"
>>>>>
>>>>> In Project/__init__.py i register the blueprint that way:
>>>>>
>>>>> from flask import Flask
>>>>> from . import config
>>>>>
>>>>> app = Flask(__name__)
>>>>> app.config.from_object(config.DevelopmentConfig)
>>>>>
>>>>> # Register blueprints and error handlers
>>>>> from .apps.admin import admin
>>>>> app.register_blueprint(admin, url_prefix='/admin')
>>>>>
>>>>> *Third*
>>>>> The problem is the following: only the localhost:5000/admin works. All
>>>>> the other routes defined in admin/account.py throw a 404 NotFound and i
>>>>> really not seing where the problem belongs.
>>>>> I have even removed my system Flask and reinstalled Flask in my
>>>>> virtualenv to see if it could solve the problem but nothing.
>>>>>
>>>>> So, if you have any idea, help me please.
>>>>> Thanks, by advance.
>>>>>
>>>>> --
>>>>> Regards,
>>>>> *
>>>>> *
>>>>> *Philippe Thécou NDIAYE*
>>>>> IT Student @ SUPINFO Lyon
>>>>> Linux Sysadmin  & Python programmer
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> "Government does not solve problems; it subsidizes them."
>>>> Ronald Reagan
>>>>
>>>
>>>
>>>
>>> --
>>> Regards,
>>> *
>>> *
>>> *Philippe Thécou NDIAYE*
>>> IT Student @ SUPINFO Lyon
>>> Linux Sysadmin  & Python programmer
>>>
>>
>>
>>
>> --
>> "Government does not solve problems; it subsidizes them."
>> Ronald Reagan
>>
>
>


-- 
Regards,
*
*
*Philippe Thécou NDIAYE*
IT Student @ SUPINFO Lyon
Linux Sysadmin  & Python programmer