python - Django 用户的 user.get_profile() 在 apache 上运行时不起作用

标签 python django apache django-users

我遇到了一个奇怪的问题。当我使用 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_profileremoved in Django 1.7 ,自 1.5 版本以来已被弃用。

您应该确保在生产中运行的 Django 版本与在开发中运行的 Django 版本相同。从长远来看,您应该重写代码,以免使用 get_profile。

关于python - Django 用户的 user.get_profile() 在 apache 上运行时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26801281/

相关文章:

python - 如何在python中的线程循环中引发异常?

python - 让我的文件夹在 twistd 中不可见/受限的最佳方法是什么?

python - Django休息框架: Including multiple choice fields in Serializer

php - sudo apachectl 开始无法在 OS X Yosemite 上运行

apache - 同一服务器,SSL 和非 SSL

python - 使用 matplotlib,如何通过叠加直方图并显示它们的比率图来比较直方图?

python - pandas 通过将列条目与多个其他列中的条目匹配来选择行

javascript - 使用 Angular 和 Django 发送文件

python - Django 可重用应用程序,具有与friendfeed 类似的功能

node.js - 在 443 端口上使用 SSL 运行 Node 应用程序(在 80 上工作)