linking a css file in your flask python app
It took me a while sifting through stack overflow to find an answer that explained what you needed to make the css code work.
https://stackoverflow.com/questions/7478366/create-dynamic-urls-in-flask-with-url-for
so, the static file, put the css code in there....
then this bit goes in your html <link> in your top header ::
https://stackoverflow.com/questions/7478366/create-dynamic-urls-in-flask-with-url-for
so, the static file, put the css code in there....
then this bit goes in your html <link> in your top header ::
<link rel="stylesheet" type="text/css" href="{{url_for('static', filename = 'styles/style.css')}}">
I guess I wasn't getting what the code did or what was code and what was instructions.
the href that is up there is the one I have typed in to make my code work. It's not instructional,
it's the raw code.
url_for is a method. It needs 'static' as an arg, and the filename = 'mystyles/style.css' as a variable
declaration to run.
So if your trying this out, the html code needs that link in it's beginning header, I put mine
after the title. You have your app file, with the bin, templates, static, appname, docs,
((and I have an images file, but I'm just getting ready to tackle that.))
here are the pic's of my file set up.
and then in static, is your styles folder, which has the file.css, in your templates file.html,
an __init__.py in your tests and appname file. ((gothonweb for me)).
the actual python script is the one up there that is app. That's the python
file I run.
Comments
Post a Comment