gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 20:47:39 24 4
gpt4 key购买 nike

我注意到,在我使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com