8π
OK, I figured it out. There was some confusion in my settings files, and I did not have STATICFILES_DIRS
correctly set.
In the end, I implemented the version-controlled settings files discussed in Two Scoops of Django 1.6, with this in my settings
:
from unipath import Path
BASE_DIR = Path(__file__).ancestor(3)
MEDIA_ROOT = BASE_DIR.child('media')
STATIC_ROOT = BASE_DIR.child('static')
TEMPLATE_DIRS = (
BASE_DIR.child('templates'),
)
STATICFILES_DIRS = (
BASE_DIR.child('myapp').child('static'),
)
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
With this, my static files are being served correctly, both in admin and without. My media files, on the other hand, did not work without changing my urls.py
in development, according to the accepted answer here. I did not have to do the same for my static files.
Anyways, I hope this helps anyone else banging their head against this particular wall.
12π
Use django-admin.py collectstatic
or go to ~/django/contrib/admin/static
and copy the admin folder(which contains the static files) and paste them into your projectβs static directory.
**EDIT**
A desperate or clumsy solution you can try for: change your STATIC_URL to β/static/β, as from question I saw this:
If I change STATIC_URL to β/static/β, then the opposite is true: the
admin is fine, but my public pages lose their static files.
Then check with inspect element/firebug
, see what urls are being served in public pages. Probably a β/β missing or added a β/β. Adjust it, and see if it works.
- Is a ModelChoiceField always required?
- Django-allauth HTML email not send
- Python-social-auth with Django: ImportError: No module named 'social_django'
3π
I faced the same issue for two times.
The way i solved it was by pasting the static files of admin into static folder mentioned in the code β
cp -r /usr/local/lib/python2.7/site-packages/django/contrib/admin/static/admin /home/ec2-user/mywork-Deployment/mywork/static
This one definitely works and saves a lot of time and troubles.
Hope it helps!
1π
First You need to try:python manage.py collectstatic
then u got any errors just follow these steps
step1
**Remove these code from you**r settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
'/home/uour project/src/project name/static/',
) //remove these lines
step2
Replace with it replace with these codes
STATIC_ROOT = os.path.join(BASE_DIR, 'static') //add these line
step3
open terminal and type:python manage.py collectstatic
- Django ListView customising queryset
- Forbidden (403) CSRF verification failed. Request aborted
- Google.maps.event.addDomListener() is deprecated, use the standard addEventListener() method instead : Google Place autocomplete Error
- Difference between self.request and request in Django class-based view
1π
If it helps anyone, I will share what the issue was with my code. Probably my stupid mistake but may save someoneβs time:
So, basically. my settings.py
variables were something like this:
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/"
STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/static/"
I inspected the admin page css src
tags and found out the URLs were like this:
(Notice two forward slashes in the URL)
https://bucket-name.s3.amazonaws.com//admin/css/login.css
.
So I changed my variables slightly and everything loaded fine.
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"
STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/static/"
That corrected the faulty URLs and static files loaded perfectly.
0π
The way that worked out for me was I referenced the static admin files in my settings.py file. I hope this helps someone π
'./static/admin/',
- How to get object from PK inside Django template?
- How to make follower-following system with django model
- FileField Size and Name in Template
- Docker + Celery tells me not to run as root, but once I don't, I lack permissions to run
0π
in my case i only set debug to True and they loaded , strange but worked somehow
- Easy Way to Escape Django Template Variables
- Sometimes request.session.session_key is None
- Celerybeat not executing periodic tasks
- A good way to encrypt database fields?
- How do I call a model method in django ModelAdmin fieldsets?