librelist archives

« back to archive

Can't use url_for('static', filename='smth') while rendering template from blueprint's view

Can't use url_for('static', filename='smth') while rendering template from blueprint's view

From:
Міша Щетінін
Date:
2012-10-13 @ 19:31
Hello. I'm creating my second flask application. It has next structure:
├── app.py
├── application
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── core
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── admin
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── views.py
│   │   │   └── views.pyc
│   │   └── authorization
│   │       ├── __init__.py
│   │       ├── __init__.pyc
│   │       ├── forms.py
│   │       ├── forms.pyc
│   │       ├── models.py
│   │       ├── models.pyc
│   │       ├── static
│   │       │   └── bootstrap.min.css
│   │       ├── templates
│   │       │   └── login.html
│   │       ├── views.py
│   │       └── views.pyc
│   └── static
│       ├── bootstrap.min.css
│       └── css
│           └── bootstrap-responsive.min.css
├── settings.py

I work on authorization package. In views i have simple method for
rendering template login.html. And I want use css files from
/application/static folder - but I can't. This <link rel="stylesheet"
type="text/css" href="{{url_for('static', filename='bootstrap.min.css')}}"
/> doesn't work and I have 404 error.

But <link rel="stylesheet" type="text/css"
href="{{url_for('login_blueprint.static', filename='bootstrap.min.css')}}"
/> works fine.

And it's pretty strange for me, because app.url_map returns me next:
Map([<Rule '/login/register' (HEAD, OPTIONS, GET) ->
login_blueprint.register>,
 <Rule '/admin/' (HEAD, OPTIONS, GET) -> admin_blueprint.index>,
 <Rule '/login/' (HEAD, OPTIONS, GET) -> login_blueprint.index>,
 <Rule '/static/<filename>' (HEAD, OPTIONS, GET) -> static>])

Maybe my problem is that I use url_prefix while registering new blueprint ?
And how can I use "global" static files from /application/static folder ?

Would someone of you be so kind to explain me this situation.

-- 
With best regards, Misha Shchetinin