在Django注册中保存配置文件 [英] Saving profile with registration in Django-Registration

查看:139
本文介绍了在Django注册中保存配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Django注册中,您可以在保存用户时保存自定义配置文件。

但我不知道文档要求我做什么。这是他们说的:


要启用自定义用户配置文件以及用户(例如, AUTH_PROFILE_MODULE 设置中指定的模型),定义一个函数,它知道如何使用适当的默认值创建和保存该模型的实例,并传递它作为关键字参数 profile_callback 。该函数应该接受一个关键字参数:



用户



用户将个人资料与。


有人可以给我

解决方案

您可以传递回调函数在你的urls.py文件。

 从mysite.profile.models导入UserProfile 


url(r'^ accounts / register / $','registration.views.register',
{'profile_callback':UserProfile.objects.create},name ='registration_register'),
pre>

根据需要将UserProfile.objects.create替换为您自己的功能。


In Django-Registration it says you can save a custom profile when you save a user.
But I have no idea what the documentation is asking me to do. Here is what they say:

To enable creation of a custom user profile along with the User (e.g., the model specified in the AUTH_PROFILE_MODULE setting), define a function which knows how to create and save an instance of that model with appropriate default values, and pass it as the keyword argument profile_callback. This function should accept one keyword argument:

user

The User to relate the profile to.

Can someone give me an example of the function that needs to be created and how to pass it as a argument?

解决方案

You can pass the callback function in your urls.py file.

from mysite.profile.models import UserProfile


url( r'^accounts/register/$',      'registration.views.register',
        { 'profile_callback': UserProfile.objects.create }, name = 'registration_register' ),

Substitute your own function for UserProfile.objects.create as needed.

这篇关于在Django注册中保存配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆