Forums

Extending Admin CSS

On my local machine I've extended admin/base.html as well as used extrastyle to tweak the Admin CSS.

{% block extrastyle %} <link rel="stylesheet" href="{% static 'css/admin.css' %}"> {% endblock %}

All is working fine...on my local machine

Git pulled to my PythonAnywhere site and I can see all the files have updated correctly BUT can't see the CSS updates to my Admin area (at PythonAnywhere). I've double checked the path under the Web tab and it's correct. I've refreshed the server as the Web tab suggests. Still can't get Admin to shows those changes.

I've also done collectstatic a few times (no files are modified says the report after doing that) and double-checked that settings.py contained ''django.contrib.admin'. All is good.

Can you offer any insight?

Mind you the default CSS for Admin, Restframework, Import-Export all show correctly so I know the static path is correct. Just can't get those updated tweaks to the Admin area I've made.

Thanks for your help.

when you collect static, is the new css files collected to the folder specified in your /static/ url-directory mapping?

Yes, it appears that way. Aftering collecting static, a 'static' folder appears at the same level as my manage.py.

Looking at my settings.py file here's what I have:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'efl_api/static')
]

When I look into my 'static file I can see the CSS and JS files collected there that are suppose to extend Django's Admin.

For what it's worth her's my HTML file that I'm using to extend and tweak Admin area:

{% extends 'admin/base.html' %}
{% load static %}
{% block branding %}
    <h1 id="head">
    <img src="{% static 'img/logo_noText.svg'  %}" alt="logo" height="100" width="100" class="brand_img">
    DATA API...</h1>
{% endblock %}
{% block extrastyle %}
    <link rel="stylesheet" href="{% static 'css/admin.css' %}">
{% endblock %}

Have a look at our guide to debugging issues with static files here: http://help.pythonanywhere.com/pages/DebuggingStaticFiles/

No luck.. even with making sure the paths were absolute. I've written tech support and once this gets sorted out, I'll post the solution.

The help page I linked to mentions 3 pieces of information that are necessary to debug issues with static files. Choose an example file that is not working and provide those 3 pieces of information so we can see what is wrong.

Try this instead:

<link rel="stylesheet" href="{{ url_for('static', 'css/admin.css') }}">

Is it working now?

PythonAnywhere tech support help me solve this. Hats off to them for their diligence with all the back and forth we did. While the settings on my localmachine worked, they didn't work on the PythonAnywhere server. You may have the same problem . It's a small fix but it's a big difference. See below.

There's an error in that TEMPLATES setting -- instead of

'DIRS': [os.path.join(BASE_DIR, 'templates')],

you have

'DIRS': [os.path.join(BASE_DIR), 'templates'],

-- note the position of the close round bracket. I think the incorrect version might work on your local machine because you're probably using "cd" to navigate to the directory that is represented as BASE_DIR in the settings, and the "templates" folder in the current working directory is on the search path by default.

If you correct the line in your settings.py, and then reload the website from the "Web" page, I think it will work.

[edit by admin: formatting]