Upon Shadows
Upon Shadows

Reputation: 21

DJANGO 4.1 manage.py invalid syntax when trying to run collectstatic

Project Folder Structure

-Project
--app1
--app2
--static

static folder has all static files for all apps.

Settings.py

try:
    SECRET_KEY = os.environ["SECRET_KEY"]
except KeyError as e:
    raise RuntimeError("Could not find a SECRET_KEY in enviroment") from e

STATIC_URL = 'static/'

STATIC_ROOT = "/var/www/191.96.1.180/static"

STATICFILES_DIRS = [
    os.path.join(BASE_DIR,  'static/')

ERROR: File "manage.py", line 17 ) from exc ^ SyntaxError: invalid syntax

pip list: pip list 1 pip list 2

So. My problem is when running python manage.py collectstatic on the developement server on my local machine it works. it saves all static files on the path from settings.py when i try to run python manage.py collectstatic on my linux server i get this error. It is not due to python version or django version i have checked.

What I've tried and the errors:

So when i try running those commands thats what i get.

python manage.py runserver

Runs

python3 manage.py runserver

Runs

if i try
sudo python manage.py runserver
INVALID SYNTAX

sudo python3 manage.py runserver
Can't find DJANGO_SECRET_KEY ( I have gotten the secret key variable | source ~/.DJANGO_SECRET_KEY )

python manage.py collectstatic
PermissionError: [Errno 13] Permission denied: '/var/www/191.96.1.180'

python3 manage.py collectstatic
PermissionError: [Errno 13] Permission denied: '/var/www/191.96.1.180'

sudo python manage.py collectstatic
INVALID SYNTAX

sudo python3 manage.py collectstatic
Can't find Secret Key

Upvotes: 0

Views: 627

Answers (2)

Upon Shadows
Upon Shadows

Reputation: 21

I fixed the issue, The main reason it was throwing errors was permissions.

needed to add www-data as owner of permissions to the whole path for staticfiles

var/www/

Upvotes: 0

ilyasbbu
ilyasbbu

Reputation: 1749

Try it with python3:

python3 manage.py collectstatic

Upvotes: 0

Related Questions