gpt4 book ai didi

python - django.core.exceptions.ImproperlyConfigured : Requested setting USE_I18N

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:23 28 4
gpt4 key购买 nike

我正在从一本书中学习 django。根据说明,我在views.py存在的同一目录中创建了一个forms.py文件。在文件中我编写了以下代码:

from django import forms

class ContactForm(forms.Form):
subject = forms.CharField()
email = forms.EmailField(required = False)
message = forms.CharField()

然后通过 env_mysite\scripts\activate 进入虚拟环境后,我启动了 python。之后我输入:

from mysite.forms import ContactForm
f = ContactForm()

但是在很多文件路径之后我收到以下消息

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.

我打开了setting.py文件,USE_I18N为True

我刚刚按照教程书 I 中的说明进行操作,但不明白这里出了什么问题。你能帮忙吗

最佳答案

您的项目的该部分(您在那里创建的表单)或该语言代码配置似乎没有任何问题。看来您只是没有在 shell 中指示要运行哪个 Django 项目。

请引用this answer.

命令:运行此命令:python manage.py shell

通过此,您可以访问您的模型和表单

关于python - django.core.exceptions.ImproperlyConfigured : Requested setting USE_I18N,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47621308/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com