0

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

2 Answers2

0

Try it with python3:

python3 manage.py collectstatic
ilyasbbu
  • 1,468
  • 4
  • 11
  • 22
  • Thanks a lot for the answer. I edited the post if you wanna take a look. already tried it with python 3 – Upon Shadows Mar 09 '23 at 08:39
  • `Can't find DJANGO_SECRET_KEY` - have you checked your secret key in settings? – ilyasbbu Mar 09 '23 at 08:59
  • Yes i have and the secret_key is there, I would not be able to make it run with runserver , if key was absent – Upon Shadows Mar 09 '23 at 09:00
  • try: SECRET_KEY = os.environ["SECRET_KEY"] except KeyError as e: raise RuntimeError("Could not find a SECRET_KEY in enviroment") from e and secret key is in enviroment variable – Upon Shadows Mar 09 '23 at 09:02
  • have a look at this https://stackoverflow.com/a/21797786/16475089 – ilyasbbu Mar 09 '23 at 09:07
  • I just tried it , still says permission denied. with python3 and if i try it with sudo python3 it says 'Could not find a SECRET_KEY in enviroment' but i have gotten the key with 'source ~/DJANGO_SECRET_KEY'... I really dont know what's going on – Upon Shadows Mar 09 '23 at 09:13
0

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/