Forums

My CSS is not loading.

Hi, My CSS code is not loading. I am using the Flask framework, and my CSS is stored in a file location that looks like this: /home/beackers/mysite/templates/css/<br> I just <link rel="stylesheet" href="css/styles.css"> my styles into my HTML page, but nothing loads: my CSS, my images. Nothing! <br> Is there a way to fix this?<br> Thanks!

It sounds like you need to set up your static file mappings, which allow you to specify specific URLs on your site that should be set up to serve up the files from specific directories. This help page has the details.

Okay, thanks! That worked. For those of y'all who didn't follow and don't really want to go to other pages, you have to set up static file mapping. Check the help page giles mentioned above for details on how this works. To set this up:

  1. Go to PythonAnywhere.com and click the Web link at the top.
  2. Scroll down the page to the Static Files heading. (Hint: it's below the "Log files" heading.)
  3. Click "Enter URL" and enter the link. I used "/static/".
  4. Click "Enter path" and enter where the URL should lead.
  5. Reload the site.

This is how I got set up: (picture)

Excellent, glad you got it working and thanks for sharing the details!

One thing I would suggest is moving your static files directory outside your templates directory, though. With the config you have right now, if someone went to http://yoursite.pythonanywhere.com/static/template_with_secret_stuff_in_it.html, they'd get that template, which might be a security concern. I'd normally put the static directory at the same level as the templates one.