0

I am getting PermissionError: [Errno 13] Permission denied: while I am running collectstatic command.

Previously I was used s3 for static files, but I don't want to use that. I was switching back to Django's Native static handler. I reverted the settings and removed STATICFILES_STORAGE. But now I started getting PermissionError.

I even changed static folders permissions to 777 but that didn't help. I tried creating a new project But in that project, collectstatic command is working fine. I also took a clone of the same project at 2 different locations on my system but it was also not working.

The static folder owner is also correct.

drwxr-xr-x  6 rohit.chopra domain users 4096 Jul  4 13:24 static/
drwxr-xr-x  2 rohit.chopra domain users 4096 Jul  4 13:22 templates/

Setting.py

# STATICFILES_DIRS = [
#     os.path.join(BASE_DIR, 'static'),
# ]
# STATIC_URL = 'https://%s/%s/' % (AWS_S3_CUSTOM_DOMAIN, AWS_LOCATION)
# STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

DEFAULT_FILE_STORAGE = 'medicine.storage_backends.MediaStorage'

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

Traceback

Type 'yes' to continue, or 'no' to cancel: yes
Copying '/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/admin/static/admin/img/icon-yes.svg'
2020-07-04 13:51:30,064 - [bugsnag] WARNING - No API key configured, couldn't notify
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 199, in handle
    collected = self.collect()
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 124, in collect
    handler(path, prefixed_path, storage)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 364, in copy_file
    self.storage.save(prefixed_path, source_file)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/files/storage.py", line 54, in save
    return self._save(name, content)
  File "/home/rohit.chopra/virtualenvs/medicine/lib/python3.6/site-packages/django/core/files/storage.py", line 317, in _save
    os.makedirs(directory, self.directory_permissions_mode)
  File "/usr/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/rohit.chopra/projects/medicine/static/admin/img'

I have commented the previous settings.

Can you guys please help me resolve this issue.

Rohit Chopra
  • 567
  • 1
  • 8
  • 24

1 Answers1

0

Are you sure you are setting the paths correctly? The STATIC_ROOT config should point to a directory outside of your app/project structure (for example, ""/var/www/medicine/static/"), and that's where the webserver you configure (Apache/Nginx/other) would go to find the files referenced in your views. From what I understand, you are pointing the STATIC_ROOT to a directory inside your project.

So basically, there are three things to configure:

  • STATIC_ROOT: external directory where you want your static files to be collected and where your production webserver should search for them. For your development server, you don't need to collect static files, as they are served directly by the django.contrib.staticfiles app.
  • STATIC_URL: the relative URL that will be added in your templates when you use the {% static %} templatetag.
  • if you want Django to search for static files to collect in places other that a directory named static under your project app modules, you can define those places using the STATICFILES_DIRS setting.
Joseba S.
  • 181
  • 7
  • Yes, `STATIC_ROOT` directory is right. It was working fine before I have added S3. Now I don't want to use S3 anymore and I was reverting the setting but now it is not working. – Rohit Chopra Jul 04 '20 at 19:10
  • but is your `STATIC_ROOT` pointing to a folder inside your project? I think that is a source for issues... – Joseba S. Jul 04 '20 at 20:23
  • That is not the issue. I have also tried putting it outside. I am getting the same error in that case also. – Rohit Chopra Jul 04 '20 at 20:25
  • ok... the other thing I can think of is that is something related with the current `umask` value when you execute the code... but I understand that should also make it fail in a plain new project... – Joseba S. Jul 04 '20 at 20:45