python - 使用 Django 注册应用程序在 Django 中处理帐户/个人资料的好地方在哪里?

标签 python django django-registration django-profiles

我注意到,在我使用 Django 注册登录后,它会将我重定向到 accounts/profile/。默认情况下Django注册的url.py不处理accounts/profile/,所以我需要自己创建。

其实这个问题有三个方面:

  1. 为什么登录后会跳转到accounts/profile/?有没有办法改变它?最好在成功登录后,我希望 Django 重定向回登录页面之前的页面。
  2. 如果我要为 accounts/profile/ 创建自己的 View 和模板,那么我应该把它放在哪里? Django 的内置 users (auth_user) 在项目内的所有 Django 应用程序之间共享,所以我应该将 view.py 放在项目中文件夹而不是 app 文件夹内?
  3. 或者 Django profile实际上会处理整个 account/profiles/ 的事情吗?我已经用我自己的 UserProfile 扩展了 Django 的 User 类,但它更像是 User 表的附加字段,而不是实际的“配置文件”(我没有创建头像或类似的东西,只是简单的东西,比如地址和电话号码,但最重要的是,我的应用依赖的一些自定义用户类型。

最佳答案

Why does after logging in, it redirects to accounts/profile/? Is there a way to change that? Preferably after successfully logging in I would like Django to redirect back to the page before the login page.

只需更改设置 LOGIN_REDIRECT_URL

If I were to create my own view and template for accounts/profile/, then where should I put it? Django's built-in users (auth_user) is shared among all Django apps inside a project, so should I place the view.py in the project folder and not inside the app folder?

我喜欢在每个项目中创建一个名为“project_specific”的应用。这就是我放置所有不可重复使用的东西并且与许多应用程序结合的地方。

您也可以在项目级别创建 views.py,但与制作项目特定的应用程序相比,这有点困惑。

实际上,你把它放在哪里并不重要。

Or does Django profile actually takes care of this whole account/profiles/ thing? I already extended Django's User class with my own UserProfile, but it's more like additional fields to the User table than an actual "profile" (I didn't create avatars or anything like that, just simple stuff like addresses and phone numbers, but most importantly, some custom user types that my app depends on).

这不是添加额外用户字段的方法。我建议您阅读 Storing additional information about users 上的文档.

关于python - 使用 Django 注册应用程序在 Django 中处理帐户/个人资料的好地方在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9835760/

相关文章:

python - 密码重置功能 Django-Registration-Redux 应用程序

python - Xpath 提取某些字符之间的日期并用作日期

python - Pygame如何设置自动射击一定的延迟

python - sklearn 未知标签类型

python - 在对象的 __class__ 属性上设置属性

jquery - 如何将 django View 与 jquery 自动保存一起使用?

python - 如何覆盖 Django-Registration 1.0 版中的默认注册表单?

python - django-registration:由于密码字符无效,中国用户无法注册

python - 使用 XOR 运算符确定整数列表中是否存在重复项

python - 使用 django ORM 进行高级排序