Hello all,
after creating a my own static folder, I have noticed that the admin page css is not loading, although I see that the browser is making the requests.
Here are my static folders (after trying py manage.py collectstatic
a new static folder was created, containing admin static folder too) currently I can not find a solution. Thanks for the help!
additionally here are my settings file, DEBUG is True:
STATIC_URL = ‘static/’
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
MEDIA_URL = ‘media/’
MEDIA_ROOT = os.path.join(BASE_DIR, ‘media’)
Welcome @ardaakyazi !
Please provide more details about your issue. Is this in a development environment using runserver, or a deployment/production environment using something like uwsgi or gunicorn?
Please post your root urls.py file, along with your INSTALLED_APPS
and STATICFILES_DIRS
(if you have one) settings.
Also, please show the complete directory structure of your project.
Side note: Do not post images of code or directory listings here. Copy/paste the text into the body of your post, between lines of three backtick - ` characters. This means you’ll have a line of ```, then the code (or template, error message, etc), then another line of ```.
Thanks for the quick reply!
I am running in development mode.
my INSTALLED APPS:
[
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'WebShop',
'rest_framework'
]
my urls file:
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('WebShop.urls'))
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + \
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I am quite new to Django, and to posting threads, so side notes are much appreciated
Good.
Now, you wrote:
What specific css files are you seeing the requests for? What are the responses being returned?
(Copy/paste the portion of your runserver log showing these requests, between lines of ``` as described above.)
[19/Aug/2024 15:51:58] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4158
[19/Aug/2024 15:52:01] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4158
[19/Aug/2024 15:52:05] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4158
[19/Aug/2024 15:52:05] "GET /static/admin/css/base.css HTTP/1.1" 200 21544
[19/Aug/2024 15:52:05] "GET /static/admin/js/nav_sidebar.js HTTP/1.1" 200 3063
[19/Aug/2024 15:52:05] "GET /static/admin/css/dark_mode.css HTTP/1.1" 200 2682
[19/Aug/2024 15:52:05] "GET /static/admin/js/theme.js HTTP/1.1" 200 1943
[19/Aug/2024 15:52:05] "GET /static/admin/css/login.css HTTP/1.1" 200 958
[19/Aug/2024 15:52:05] "GET /static/admin/css/responsive.css HTTP/1.1" 200 17905
[19/Aug/2024 15:52:05] "GET /static/admin/css/nav_sidebar.css HTTP/1.1" 200 2810
It looks like the requests are being satisfied. What exactly appears to be the problem? (If it’s something with how the page is being rendered, go ahead and post an image of the page you’re seeing.)
The webpage looks like this.
I cleared the browser cache as well, in case that’s important.
Try it from an “incognito” or “private” window in your browser.
Also, make sure that all instances of runserver have been stopped before starting it again.
Finally, what operating system are you developing on? What version of Python and Django are you using?
I have tried the incognito, didn’t work.
I have restarted all my instances too. Still no change.
I am using Python 3.11.5 and Django 5.0.3.
Stop the instances that you know are running, and try to access the site. If you’re still able to connect, then there’s a hidden instance still running.
Also, what operating system are you using and developing this on?
There were no other instances running, and my operating system is Windows 11.
Would you like to remove ‘rest_framework’ from NSTALLED APPS?
I think I’ve seen a post before about rest_framework being the problem.
Please clarify your directory structure.
You have a parent directory named CookieCorner, and an inner directory named CookieCorner. You show a directory named static
containing subdirectories named admin
, js
, rest_framework
and WebShop
. Is this static
directory in the parent directory or the inner directory?
(Side note: Running in development mode with DEBUG=True, you should delete the contents of that static directory.)
I asked earlier if you had a STATICFILES_DIRS
setting - do you have this setting?
Are you running with DEBUG=True or DEBUG=False?
Do you have the STATICFILES_FINDERS
in your settings?
I have solved the issue.
It was indeed due to the directory structure. After recreating the project and moving the static files in to the app folder WebShop
, and setting the static urls:
STATIC_URL = ‘static/’
MEDIA_URL = ‘media/’
This has solved the issue for me when DEBUG = True
, I assume I will have to set the other parameters before going into production mode.
Thanks for the help!