在Django注册中保存配置文件 [英] Saving profile with registration in Django-Registration
问题描述
在Django注册中,您可以在保存用户时保存自定义配置文件。
但我不知道文档要求我做什么。这是他们说的:
要启用自定义用户配置文件以及
用户
(例如,AUTH_PROFILE_MODULE
设置中指定的模型),定义一个函数,它知道如何使用适当的默认值创建和保存该模型的实例,并传递它作为关键字参数profile_callback
。该函数应该接受一个关键字参数:
用户
用户
将个人资料与。
有人可以给我
您可以传递回调函数在你的urls.py文件。
从mysite.profile.models导入UserProfile
pre>
url(r'^ accounts / register / $','registration.views.register',
{'profile_callback':UserProfile.objects.create},name ='registration_register'),
根据需要将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 theAUTH_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 argumentprofile_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屋!