Django export env error : not a valid identifier

Issue

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 ?

Solution

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.)

Answered By – 9769953

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published