Unable to load Djangostatic file

Asked 2 years ago, Updated 2 years ago, 64 views

Due to various reasons, I reinstalled the server and rebuilt it, but I cannot load the static file of Django.

<About the Environment>
·GMO Cloud VPS
·CentOS 8
·nginx
·Django 2.2
·python 3.6
·Virtual environment venv

<settings.py>

STATIC_URL='/static/'
STATIC_ROOT='/home/[User]/Django/[file]/[project name]/[app name]/static/'

<nginx.conf>

 location/static {
    root/home/[User]/Django/[file]/[project name]/[app name]/static;
    }

<Tree>

.
├-- Project Name
│   -- --_init__.py
│   -- --__pycache__
│   -- __ --_init__.cpython-36.pyc
│   │ set --settings.cpython-36.pyc
│   │ -- -- urls.cpython-36.pyc
│   w --wsgi.cpython-36.pyc
│   -- -- settings.py
│   -- -- urls.py
│   -- -- wsgi.py
├-- App Name
│   -- --_init__.py
│   -- --__pycache__
│   -- -- admin.py
│   -- -- apps.py
│   -- --media
│   -- --migrations
│   -- -- models.py
│   -- -- static
│   │ c -- css
│   i --images
│   -- --templates
│   -- -- tests.py
│   -- -- urls.py
│   -- -- views.py
└-- └── manage.py

Before the reinstallation, it was loaded without any problems, but after the reconfiguration, it was not loaded at all.
Please let me know if you need any information.

python django

2022-09-30 17:38

1 Answers

I tried many things and it was solved.

Conclusion

Resolve permission issues

Background to resolution

After reviewing the nginx error log, I noticed that there was a "13: Permission denied" and tried to review the permissions, and it was resolved.

Solution

Granted execution privileges to all root directories.

 sudo chmod+x/home
sudo chmod+x/home/[User]
sudo chmod+x/home/[User]/Django
sudo chmod+x/home/[User]/Django/[file]/[project name]
sudo chmod+x/home/[User]/Django/[file]/[project name]/[app name]

The static file is now loaded successfully.

Once again, I would like to thank everyone for their efforts to solve this problem.
When I think about it, it was a rudimentary mistake.

From now on, we will continue to develop while looking closely at the error log.
Sorry for the trouble.


2022-09-30 17:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.