我是Django的初学者。我需要设置一个网站,每个用户都有一个个人资料页面。我见过django管理员。用户的配置文件页面应该存储一些只能由用户编辑的信息。任何人都可以指出我怎么可能?任何教程链接都会非常有帮助。另外,是否有任何django模块,可用于设置用户页面。在Django中创建用户个人资料页面
回答
如果用户创建GET
请求或在创建POST
请求时更新用户的个人资料数据,您只需创建一个可供已认证用户使用的视图并返回配置文件编辑表单。
大部分工作已完成,因为编辑模型的编号有generic views,例如UpdateView。您需要扩展的是检查经过身份验证的用户并为其提供您想要提供编辑的对象。这是MTV黑社会中的视图组件,它提供编辑用户个人资料的行为 - Profile
模型将定义user profile,模板将以离散方式提供演示。
所以这里的一些行为,你扔一个简单的解决方案:
from django.contrib.auth.decorators import login_required
from django.views.generic.detail import SingleObjectMixin
from django.views.generic import UpdateView
from django.utils.decorators import method_decorator
from myapp.models import Profile
class ProfileObjectMixin(SingleObjectMixin):
"""
Provides views with the current user's profile.
"""
model = Profile
def get_object(self):
"""Return's the current users profile."""
try:
return self.request.user.get_profile()
except Profile.DoesNotExist:
raise NotImplemented(
"What if the user doesn't have an associated profile?")
@method_decorator(login_required)
def dispatch(self, request, *args, **kwargs):
"""Ensures that only authenticated users can access the view."""
klass = ProfileObjectMixin
return super(klass, self).dispatch(request, *args, **kwargs)
class ProfileUpdateView(ProfileObjectMixin, UpdateView):
"""
A view that displays a form for editing a user's profile.
Uses a form dynamically created for the `Profile` model and
the default model's update template.
"""
pass # That's All Folks!
对文档字符串使用双引号以正确语法突出显示 – glarrain 2012-09-14 17:54:32
谢谢,您的权利! – 2012-09-14 20:39:42
感谢你 - 非常有用!有两件事我不得不改变以使其工作:而不是'@ login_required',你需要'@method_decorator(login_required)'(从'django.utils.decorators'导入)。而不是使用'BaseUpdateView'使用'UpdateView',否则会出现'render_to_response'丢失的错误。 – 2012-09-19 11:14:08
可以
- 创建用于存储有关用户
- 轮廓信息的另一个模型添加
AUTH_PROFILE_MODULE='yourprofileapp.ProfileModel'
到的settings.py 在配置文件编辑视图中,只允许登录的用户编辑自己的配置文件
例如:
@login_required def edit_profile(request): ''' edit profile of logged in user i.e request.user '''
您也可以确保每当新用户创建用户的配置文件还使用Django的信号
创建从Django文档阅读storing additional information about users
- 1. Django:建立用户个人资料页面?
- 2. WordPress为用户创建个人资料页面
- 3. 每个用户的Django个人资料页面
- 4. 我需要让用户在飞行中创建个人资料页面
- 5. Facebook个人资料页面
- 6. 个人资料页面PHP
- 7. 在MeteorJS中呈现用户个人资料页面
- 8. Drupal的7 - 在个人资料页面
- 9. 在用户注册时创建一个自定义用户个人资料页面?
- 10. 个人资料页面 - URL参数
- 11. Twitter iOS个人资料页面配置
- 12. Facebook图形API:链接到用户的个人资料页面
- 13. 限制用户到他们的个人资料页面
- 14. php-编辑用户的个人资料页面
- 15. 的用户个人资料页面生成
- 16. php - 编辑用户的个人资料页面
- 17. 如何重写用户个人资料页面?
- 18. Drupal 7编辑用户个人资料页面
- 19. Django的创建初始化群体,延长超级用户的个人资料
- 20. 如何获取新创建用户的个人资料?
- 21. Drupal:我如何将个人资料标记传递给用户个人资料页面?
- 22. 如何在外部网站页面创建Facebook个人资料克隆?
- 23. 如何翻译显示在用户个人资料页面或我的应用程序个人资料页面中的我的应用程序名称?
- 24. Swift-通过PFQueryTableViewController创建一个像Twitter或Instagram的个人资料页面
- 25. Ruby on Rails的创建个人资料页
- 26. 帐户创建/登录查看个人资料
- 27. 如何添加按钮,用户的个人资料页在Drupal
- 28. 创建链接到新闻源阵列的朋友的个人资料页面
- 29. 的个人资料页使用案例
- 30. 跑道:如何获取联系人/用户个人资料创建日期?
你已经开发了什么? – Dean 2012-01-28 15:50:28
我已经完成验证。 – jvc 2012-01-28 16:02:23
http://stackoverflow.com/questions/8177289/django-profiles http://stackoverflow.com/questions/7313336/django-multiple-user-profiles-subprofiles http://stackoverflow.com/questions/3100521/django-registration-and-multiple-profiles http://stackoverflow.com/questions/4171083/is-there-a-django-app-that-can-manage-your-users-profiles http ://stackoverflow.com/questions/7173279/django-registration-and-django-profiles http://stackoverflow.com/questions/2654689/django-how-to-write-users-and-profiles-handling- in-best-way http://stackoverflow.com/questions/1910359/creating-a-extended-use – 2012-01-28 16:20:44