0

I am using a DRF serializer in my project as below

# my_serrializers.py
from rest_framework import serializers


class TssUpdateExtraVarsSerializer(serializers.Serializer):
    cluster_name = serializers.CharField(required=True)


class TssUpdateSerializer(serializers.Serializer):
    extra_vars = TssUpdateExtraVarsSerializer(required=True)

It works fine when I send a request and it handles the job.

But if I open a python console (the one in my project's venv) as below:

#python console
from my_serializers import TssUpdateSerializer

s = TssUpdateExtraVarsSerializer(data={"a": 1})

s.is_valid()

I get this error

django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

what is the reason for it and how to fix it.

I want to be able to play with it outside of django. is it possible? how?

Amin Ba
  • 1,603
  • 1
  • 13
  • 38
  • 1
    How are you opening up your Python console? You might want to use `python manage.py shell` so you have Django set up. See also [this question](https://stackoverflow.com/q/8047204/9374673). – Mihai Chelaru Oct 26 '22 at 13:53
  • 2
    dont want to do it with `python manage.py shell`. I am looking for a way to use those classes independently of django – Amin Ba Oct 26 '22 at 13:55
  • Check my edited comment, linked to a question asking something similar. If that's not what you require, please clarify how your use case differs. – Mihai Chelaru Oct 26 '22 at 13:55
  • 1
    I open python 3 console by going to terminal (venv activated) and typing `python` – Amin Ba Oct 26 '22 at 13:55

0 Answers0