本地设置中的身份验证模型查询会引发错误
我正在我的 local_settings
中执行对 auth.models.User
的查询,因为我在多个测试中需要一个 User 实例。
from django.contrib.auth.models import User
TEST_USER = User.objects.all()[0]
这引发了一个错误:
没有名为 simple_backend 的模块
这样,与 Django 开发服务器的连接就会断开。此消息是什么意思?它是如何发生的?
I am executing a query to auth.models.User
in my local_settings
, for the fact that I need a User instance in several tests.
from django.contrib.auth.models import User
TEST_USER = User.objects.all()[0]
This raised an error:
No module named simple_backend
With that, the connection to the Django development server is dropped. What does this message mean, and how does it happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你没有说 local_settings 是在哪里导入的,但如果它在主 settings.py 中,那么你就不能这样做。设置是设置整个 Django 项目的地方,使用在设置它的文件中设置的数据库引擎是没有意义的。
如果您在多个测试中需要某些内容,请定义一个设置该值的测试类,然后使所有其他测试成为该类的子类。
You don't say where local_settings is imported, but if it's in the main settings.py, then you can't do that. Settings is where the whole Django project is being set up, and it doesn't make sense to use the database engine that's being set up in the file that's setting it up.
If you need something in several tests, define a test class that sets that value up, then make all your other tests subclass that class.