Skip to content

Issue with ALLOW_ORIGINS Environment Variable Causing Pydantic Error #486

Answered by tarsil
prashikdewtale10 asked this question in Q&A
Discussion options

You must be logged in to vote

@prashikdewtale10 Ok there might be something wrong on your side that I'm not aware but this is how I made it work cleanly in my codebase that also uses the cors_config.

from lilya.environments import EnvironLoade

loader: EnvironLoader = EnvironLoader()

def validate_list(value: str) -> list[str]:
    if isinstance(value, list):
        return value
    return value.split(",")


class DevelopmentSettings(AppSettings):
    ...
    @property
    def cors_config(self) -> CORSConfig:
        """
        Allow CORS for all origins.
        This is important for the frontend to communicate with the backend.
        """
        return CORSConfig(
            allow_origins=loader("ALLOWED_ORIGINS"

Replies: 2 comments 18 replies

Comment options

You must be logged in to vote
10 replies
@tarsil
Comment options

@prashikdewtale10
Comment options

@tarsil
Comment options

@prashikdewtale10
Comment options

@tarsil
Comment options

Comment options

You must be logged in to vote
8 replies
@tarsil
Comment options

@tarsil
Comment options

Answer selected by prashikdewtale10
@prashikdewtale10
Comment options

@tarsil
Comment options

@prashikdewtale10
Comment options

@tarsil
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants