Home > database >  Django export env error : not a valid identifier
Django export env error : not a valid identifier

Time:08-04

I'm coding in Django ,and want to export the env in build.sh ,the env is an email attachment file type list,I have put it in a python list in the build.sh like this:

export PROJECT_EMAIL_FILE_TYPE = [".txt", ".doc",".docx","xls","xlsx","csv",".pdf", ".jpg",".png", ".jpeg",".html",".ppt"]

Then I plan to call it from the settings.py

PROJECT_EMAIL_FILE_TYPE = os.environ.get('PROJECT_EMAIL_FILE_TYPE ')

And then called it any place I want by :

settings.AEGIS_EMAIL_FILE_TYPE

However when I export it by directly copy that line and enter in Linux there was an Error:

-bash: export: `=': not a valid identifier
-bash: export: `[.txt,': not a valid identifier
-bash: export: `.doc,.docx,xls,xlsx,csv,.pdf,': not a valid identifier
-bash: export: `.jpg,.png,': not a valid identifier
-bash: export: `.jpeg,.html,.ppt]': not a valid identifier

Any friend can help ? How should I do this properly ?

CodePudding user response:

In your shell script:

export PROJECT_EMAIL_FILE_TYPES=".txt,.doc,.docx,xls,xlsx,csv,.pdf,.jpg,.png,.jpeg,.html,.ppt"

In your Python code:

PROJECT_EMAIL_FILE_TYPES = os.environ.get('PROJECT_EMAIL_FILE_TYPES').split(',')

(Use proper variable names; here, for example, plural when the variable contains a list.)

  • Related