skip to Main Content

I am configuring a new Django web site using Cpanel. After completing the whole procedures and run this code python manage.py collectstatic I am getting the following error:

    Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 195, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
    return module.Command()
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 32, in __init__
    self.storage.path('')
  File "/home/massvnrc/virtualenv/mysite/3.7/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py", line 48, in path
    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.

Bellow is the configuration that is raising the error:

STATIC_URL = '/static/'
MEDIA_URL='/media/'
STATICFILES_DIRS=[BASE_DIR+"/assets",]
MEDIA_ROOT='/home/****/public_html/media'
STATIC_ROOT='/home/****/public_html/static'

I honestly don’t know where is the erro and the similar issues do not help me to solve the problem.

Please assist me

2

Answers


  1. In settings, the proper configuration for static would like this

    STATIC_URL = '/static/'
    STATIC_ROOT = '' #This tell where the static file location inside static dirs. Empty means current
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'), #Note this is tuple, and path is /home/../DjangoFolder/static
    )
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    MEDIA_URL = '/media/'
    

    Your file structure is like

    DjangoProject #(This is the BASE_DIR path)
     |-manage.py
     |-Django app folder
     |-static #<- you created this folder
     |-media #<- you created this folder
    

    As much as you can avoid using paths as a string as there can be issues while migrating to production. Instead, use ‘os’ library to get the current directory path. Usually, all folders are accessible from BASE_DIR if you configure it like documented in Django.

    Login or Signup to reply.
  2. As I am seeing in your code you need to add STATIC_ROOT=’ ‘ in your settings.py
    What python manage.py collectstatic do is to collect the static files from the directory.

    put your static files folder into your app folder.

    I have encountered the same error.Therefore,I suggest you to give your static files path first and then run the collectstatic command again.

    Here is the procedure:

    Step1: Put your static files into your project app folder first.

    Step2: Add this STATIC_ROOT=’path where you want to collect those static files’

    where do you want to extract those static files.

    If the issue persists or you need more help feel free to comment

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search