Forums

Pythonanywhere css not loading. link href problem?

Hi

In my HTML I am trying to link to an external CSS file. All my many attempts look like the following

<head> <link rel="stylesheet" type = "text/css" href="mysite/assets/styles.css" /> </head>

In none of the variants, where I change the href value, can I get the CSS to load.

I have tried all kinds of variations on the href:

" styles.css" "/styles.css" "assets/styles.css" "mysite/assets/styles.css" etc. etc

and placed copies of styles.css in various directories

/home/crlong/mysite /home/crlong/mysite/assets /home/crlong/mysite/templates  <== this is location of the html page

and in all cases I get error messages like the following when I try to debug using the browser

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - http://cliverlong.pythonanywhere.com/styles.css or HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). GET - http://cliverlong.pythonanywhere.com/mysite/assets/styles.css etc. etc.

I have looked at various documentation on HTML link href on the web and in Pythonanywhere Forums and I can’t work out exactly how this links together – assuming my value of the href is the problem.

If this is documented somewhere clearly and I just can’t find it, please just point me at that description.

Much appreciated.

Clive

See http://help.pythonanywhere.com/pages/StaticFiles/ and http://help.pythonanywhere.com/pages/DebuggingStaticFiles/

I couldn't figure it out either and these articles just make it more confusing. I simply used an absolute path reference and it worked

That's one of the possible ways.

I got it to work by adding the directory path as a static file.

In "Static Files": set URL: "/static/" set Directory: "/home/#your_username/#your_filepath_to_the_folder_containing_the_css_file/"

Finally, in the html document: <link rel="stylesheet" href="/static/#your_filename">

Glad to hear that you made it work!