让django-registration和django-profile一起工作

6 投票
1 回答
1127 浏览
提问于 2025-04-17 04:31

我正在设置一个新的 Django 项目,并想使用提供的 django-registration 和 django-profile 应用。我通过 easy-install 安装了这两个应用,并成功让 django-registration 正常工作。接下来的步骤是把 django-profile 应用连接到已经工作的部分。django-registration 提供了一项服务,可以重定向到一个 URL,这个 URL 在 settings.py 文件中的 LOGIN_REDIRECT_URL 变量里定义。我猜我可以简单地把 django-profile 应用的 URL 粘贴进去来连接这两个应用(例如 '/profiles/')。

我的 settings.py 里的 AUTH_PROFILE_MODULE 设置为 'registration.User',也就是想使用 django-registration 的模型!但是我遇到了一个错误:

在 /profiles/ 处出现了 SiteProfileNotAvailable 错误,没有提供异常信息。

我尝试按照以下步骤操作:

https://bitbucket.org/ubernostrum/django-registration/src/tip/docs/index.rst
https://bitbucket.org/ubernostrum/django-profiles/src/tip/docs/overview.txt

但我不确定自己是否做对了,特别是 overview.txt 中的这一段:

对于默认使用,创建一个适合你网站的个人资料模型,并相应地设置 AUTH_PROFILE_MODULE。然后把 profiles 添加到你的 INSTALLED_APPS 设置中,创建相应的模板,并设置 URL。为了方便链接到个人资料,你的个人资料模型应该定义一个 get_absolute_url() 方法,该方法指向视图 profiles.views.profile_detail,并传递用户名。

所以我有几个问题:

  • 这是一个常见的错误吗?
  • 把 'registration.User' 设置为 AUTH_PROFILE_MODULE 是正确的吗?
  • overview.txt 中提到的“应该定义一个 get_absolute_url() 方法,该方法指向视图 profiles.views.profile_detail,并传递用户名”是什么意思?

1 个回答

3

django-registration这个东西用起来挺麻烦的,主要是因为它的文档写得不太好,而且缺少模板。现在很多Django开发者都开始用django-social-auth了:

https://github.com/omab/django-social-auth
http://django-social-auth.readthedocs.org/en/latest/index.html

你可以看看Kenneth Love是怎么把它整合到Django Packages代码里的:

https://github.com/opencomparison/opencomparison/blob/master/apps/profiles/views.py#L83
https://github.com/opencomparison/opencomparison/blob/master/settings.py#L277

撰写回答