我有以下内容:(它按预期工作)
# In <..>/profile/models.py
class UserProfile()
#In settings.py
AUTH_PROFILE_MODULE = "profile.UserProfile"
我有以下内容:(不工作)
# In <..>/profile/models/__init__.py
class UserProfile()
AUTH_PROFILE_MODULE = "profile.UserProfile"
看来 get_profile() 调用了 get_model,它正在寻找 models.py 作为文件并尝试加载它。
这是错误:
raise SiteProfileNotAvailable('无法加载配置文件' SiteProfileNotAvailable:无法加载配置文件模型,请检查项目设置中的 AUTH_PROFILE_MODULE
原因是我在配置文件应用程序中有很多类,它们都在不同的文件中并导入到:
<..>/profile/models/__init__.py
这适用于除 get_profile() 之外的所有其他内容。
有任何解决方法的提示吗?
最佳答案
有时 django 会对应用程序名称感到困惑,因此请确保:
class UserProfile(Model):
....
class Meta:
app_label = 'profile'
这将确保可以使用 profile.UserProfile 查找配置文件
关于django - 当模型不是文件而是目录时,django 中的 AUTH_PROFILE_MODULE 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9090748/