我遇到了一个奇怪的问题。当我使用 python manage.py runserver 运行 python 服务器时,我的 user.get_profile() 工作正常,一切似乎都很好,但是当我从 apache 服务器 + mod wsgi 运行相同的应用程序时我收到此 AttributeError
错误:'User' 对象没有属性 'get_profile'
。我不知道我该怎么办。
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "passportpay.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
模型.py
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
operator_id = models.CharField(max_length=20)
is_admin = models.BooleanField(default=False)
最佳答案
get_profile
为 removed in Django 1.7 ,自 1.5 版本以来已被弃用。
您应该确保在生产中运行的 Django 版本与在开发中运行的 Django 版本相同。从长远来看,您应该重写代码,以免使用 get_profile。
关于python - Django 用户的 user.get_profile() 在 apache 上运行时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26801281/