Forums

css and images not loading

Hi, my css and images load on the local but not on pythonanywhere. I've been trying to follow this answer but have some doubts:

my settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_URL = "/static/"

STATIC_ROOT = os.path.join(BASE_DIR, "static")

I'm unsure what to actually put in STATIC_ROOT - do I take the path from my local ubuntu? i.e. the one starting with /mnt?

Or do I just have to set the path in pythonanywhere? Can I edit files on the bash console?

When do I have to run manage.py collectstatic? I've just run it once, to no effect.

project structure on local:

├── static
│   ├── css
│   │   └── blog.css
│   └── images
│       └── banner.png
├── templates
│   └── suquiwrites
│       └── home.html

The line in home.html goes <link rel="stylesheet" href="../../static/css/blog.css">

Thanks in advance!

I've also just tried with <link rel="stylesheet" href="{% static 'css/blog.css' %}"> but that didn't work either.

We have a help page on debugging issues with static files

Thank you, glenn.

I'm stuck at a different point now and can't see if the steps from the tutorial are working.

I've messed up some migrations and / or pulls from Github, and got "No such column" error. I then dropped the table on sqlite, deleted all migrations files and now getting "table does not exist". Which is fine, I can see that in the dbshell.

The problem is, I can't get the migrations back. I've tried makemigrations, and another git pull. The output is that everything is up to date with Github. ls in the migration directory is blank on pythonanywhere and has 4 migrations on Github, so it's clearly not up to date.

How can I get these migrations back?

What is the output of git status?

.

On branch master
Your branch is ahead of 'origin/master' by 4 commits.
  (use "git push" to publish your local commits)
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        suquiwrites/migrations/0002_auto_20210121_1622.py
        suquiwrites/migrations/0003_auto_20210121_1626.py
        suquiwrites/migrations/0004_remove_entry_created_date.py
nothing added to commit but untracked files present (use "git add" to track)

I just tried to add the migrations manually via the files tab on pythonanywhere, that's why they are there on the bash console.

[edit by admin: formatting]

Do you have a file inside the directory suquiwrites/migrations/ that starts with 0001? If not, it sounds like you're missing your initial migration.