librelist archives

« back to archive

flask static file with blueprint

flask static file with blueprint

From:
樱宝宝
Date:
2013-02-25 @ 09:06
I use blueprint in flask.Can use every static folder in every blueprint?

files list:
wsgi.py
blog/
      views.py
      tempaltes/base.html
      static/a.js

blog/views.py:
....
blog = 
Blueprint("blog",__name__,template_folder="templates",static_folder="static")
....


bolg/tempaltes/base.html

.....
{{url_for("static",filename="a.js")}}
.....



the `url_for` return  "/static/a.js"(404) but not "/blog/static/a.js"

how to use it?Thanks

Re: [flask] flask static file with blueprint

From:
anh le
Date:
2013-02-25 @ 09:16
On Mon, Feb 25, 2013 at 4:06 PM, 樱宝宝 <xuanmingyi@qq.com> wrote:
> I use blueprint in flask.Can use every static folder in every blueprint?
>
> files list:
> wsgi.py
> blog/
>       views.py
>       tempaltes/base.html
>       static/a.js
>
> blog/views.py:
> ....
> blog =
> Blueprint("blog",__name__,template_folder="templates",static_folder="static")
> ....
>
>
> bolg/tempaltes/base.html
>
> .....
> {{url_for("static",filename="a.js")}}
> .....

It should be url_for("blog.static",filename="a.js")

greetings,

Re: [flask] flask static file with blueprint

From:
ubunoon
Date:
2013-02-26 @ 01:59
or using url_for('.static', filename='a.js')


2013/2/25 anh le <anhlh2@gmail.com>

> On Mon, Feb 25, 2013 at 4:06 PM, 樱宝宝 <xuanmingyi@qq.com> wrote:
> > I use blueprint in flask.Can use every static folder in every blueprint?
> >
> > files list:
> > wsgi.py
> > blog/
> >       views.py
> >       tempaltes/base.html
> >       static/a.js
> >
> > blog/views.py:
> > ....
> > blog =
> >
> Blueprint("blog",__name__,template_folder="templates",static_folder="static")
> > ....
> >
> >
> > bolg/tempaltes/base.html
> >
> > .....
> > {{url_for("static",filename="a.js")}}
> > .....
>
> It should be url_for("blog.static",filename="a.js")
>
> greetings,
>



-- 
DamonChen
让生活更俏皮些 <http://www.zz1788.com>