Wednesday, January 3, 2018

DJANGO - Not able to run collectstatic on a shared hosting server using cPanel

As part of setting-up a new Django application, one will need to run collectstatic in order to copy all static files.

It happens that, as I have a shared account on a hosting comp, I have no access to the prompt, the only option to execute this kind of commands was through Execute Command on cPanel:



And, when trying to run collectstatic, this is the output I was facing:

python manage.py collectstatic

You have requested to collect static files at the destination location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: Traceback (most recent call last):
File "manage.py", line 15, in <module>execute_from_command_line(sys.argv)
File "/home/user/virtualenv/mysite/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/user/virtualenv/mysite/3.5/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/virtualenv/mysite/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/virtualenv/mysite/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/user/virtualenv/mysite/3.5/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 186, in handle
if input(''.join(message)) != 'yes':
EOFError: EOF when reading a line



What I figured out is that collectstatic command was waiting for an input and I wasn't able to provide any as Execute Command from cPanel doesn't allow me to interact after you submit any command.

To overcome such limitation, I had to append the --noinput argument, so the command was successfully executed.

Another alternative, if your hosting company provides a remote MySQL access, you may be able to open a cmd prompt from your computer, connecting to the server database, so you'll be able to interact with the script as much as you need. This is what I started doing after discovered this alternative, it's easier and there are some commands that don't allow us to have a --noinput argument.

Hope this helps everyone who may face a similar problem.

1 comment: