django Static files are served, but not admin css - django

I have my website in production mode and the static files are served properly in it, with debug=False. But the admin page css are not loader. I have my static URL as /assets/, with static root as:
os.path.join(BASE_DIR,"static")
Now, I have admin folder inside the static folder. But
mysite.com/assets/admin/css/base.css
I also tried adding ADMIN_MEDIA_PREFIX='/assets/admin/ to my settings.py, which did not help
gives a 404 Error.

Related

Ignore SuspiciousFileOperation in Django

I am serving my vuejs SPA in django at /app/
Serving static files at /static/
My app is working fine served in django development, but, collectstatic fails.
My vue.config.js has:
module.exports = {
assetsDir: 'static',
}
Compiled CSS files have font urls like this:
url(../../static/fonts/materialdesignicons-webfont.ee2bb9f3.eot
This works in the browser because it can't go up 2 dirs but in the filesystem goes up 2 dirs instead of one.
Works fine in the browser, but can't be deployed. It throws SuspiciousFileOperation exceptions:
django.core.exceptions.SuspiciousFileOperation: The joined path (/mnt/c/Users/static/fonts/materialdesignicons-webfont.ee2bb9f3.eot) is located outside of the base path component (/mnt/c/Users/fede_/braced/staticfiles)
I am really stuck with this.

Redirection to Heroku : 502 Proxy Error for static files (Django app)

I have a Django app hosted on Heroku https://omegapp3.herokuapp.com and a custom domain association-omega.com that I configured to be redirected on the Heroku app.
When I go on association-omega.com, the first page (index.html) is well served but for all of the static files, I have a 502 Proxy Error. Do you know if there are any prerequisite for static files ? (I use whitenoise to serve static files).

django login screen (default setting) doesn't display properly?

My django admin page didn't display properly. Like a pure html display. Can someone help here?
I don't have the permission to upload screenshot. But you can imagine, it doesn't look the same as tutorial shows.
thanks
You probably don't have static files serving set up. If you have DEBUG turned on, you'll get this automatically with Django's development server (./manage.py runserver). If running in production, you need to set this up manually. See the docs for more info.
Basically your static files are not set up properly, some of the reasons can be :-
If you running on a server like apache, you need to have static url in settings.py and same alias in httpd.conf file of apache.
If you are running on django in built server, please try to set Debug=True, which will force django to serve those static files.
If you have debug=False in settings.py file, https://docs.djangoproject.com/en/dev/howto/static-files/
Because u really need a static files from django, sometimes you have to set the alias of django admin static files separately, which can be set in urls.py that is pointing to django package
found the issue.
I forgot to turn on
'django.contrib.staticfiles'
in setting.py file

How does the admin app work without collectstatic?

I created a new django app (with dj-static), enabled the admin app, started the server and to my surprise, the css files in the admin were available even though i did not run collectstatic.
So, I created a few static files in my static directory and then when I ran collectstatic, the CLI showed the admin static files being moved to the static root folder along with my other static files.
How does the static files for admin work without collectstatic? And if it works without collectstatic, why move it to static root?
Thanks.
You don't need collectstatic for any app when you're running under the development server. collectstatic is for moving apps' static files into a central location so that they can be served with the asset server.

Why don't the admin pages in my Django application reference the right CSS URLs?

When I visit the admin pages of my Django application, I notice that they reference CSS at addresses like admin/css/base.css. However, I noticed that the admin css files are actually located at addresses such as media/css/base.css.
Hence, the CSS does not load in my admin pages. Why is this so? I have tried to manually move the CSS files on my server to accomodate the admin page URLs, but this is unreliable since the CSS URLs referenced in the admin pages are relative (and thus change for every page).
NOTE - My previous answer is deprecated for Django 1.4, as per https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin
If you're using Django 1.4, just point the STATIC_URL setting to the appropriate location, e.g.
STATIC_URL = '/static/'
or
STATIC_URL = 'https://bucket-name.s3.amazonaws.com/static/'
and your admin static files will be automatically put at STATIC_URL+'admin/'. This is probably why your admin files reference css at /admin/css. The question is why are the actual files located at /media/css - did you manually upload them? Does collectstatic put them there? Try collectstatic and see if it puts the admin/css files in the appropriate location, and then just upload that to the server.
/static/admin/css is the default location for your admin css files. Are your settings correct?
ADMIN_MEDIA_PREFIX = '/static/admin/'
The above would cause your admin css files to be collected to /static/admin/css when you use the
python manage.py collectstatic
command. If you change it to
ADMIN_MEDIA_PREFIX = '/static/media/'
I would assume the css files would be collected at /static/media/css instead (though I haven't tested this).
Also, why does manually moving the css files not work? Not that I would recommend it (should use python manage.py collectstatic to collect all your static files for you in one consolidated location), but if you moved them to /static/admin/css that should still be what your CSS files are referencing, right?
As a note, you can make the ADMIN_MEDIA_PREFIX absolute as well. Mine are set to my s3 bucket, e.g.
ADMIN_MEDIA_PREFIX = 'https://bucket-name.s3.amazonaws.com/static/admin/'