Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在django上编辑用户配置文件_Django - Fatal编程技术网

在django上编辑用户配置文件

在django上编辑用户配置文件,django,Django,如何创建userprofile可编辑页面,并在单击提交时使用DJANGO?更新注册期间提供的详细信息(存储在数据库中的详细信息) 为用户创建注册表,就像我在我的开场白中所说的,我希望用户在登录后能够编辑注册期间提供的内容,并更新数据库中存储的以前的详细信息 我知道我需要为它创建一个视图,但还没有确定如何调用注册期间提供的详细信息。好吧,也许使用user.get_profile() forms.py views.py 下面的代码给出的错误用户名已经存在,但当我指定一个新用户名时,它会更新,虽然它不

如何创建userprofile可编辑页面,并在单击提交时使用DJANGO?更新注册期间提供的详细信息(存储在数据库中的详细信息)

为用户创建注册表,就像我在我的开场白中所说的,我希望用户在登录后能够编辑注册期间提供的内容,并更新数据库中存储的以前的详细信息

我知道我需要为它创建一个视图,但还没有确定如何调用注册期间提供的详细信息。好吧,也许使用user.get_profile()

forms.py views.py 下面的代码给出的错误用户名已经存在,但当我指定一个新用户名时,它会更新,虽然它不会更新用户名,但会更新其他字段 editprofile的views.py 用下面的代码进行分类: forms.py views.py
谢谢大家…

Django 1.5和自定义用户模型将对此有所帮助,但与此同时,您的模型表单设置很好

要从其对象的实例初始化ModelForm,请执行以下操作:

user_profile_form = RegistrationForm(request.POST, instance=request.user.get_profile())
该行中的
request.POST
允许您使用用户的输入更新
user\u profile\u表单
对象。它将很好地将实例中的现有数据与用户提供的新信息合并在一起

然后,您可以将其打印到视图中,也可以通过以下方式保存:

if user_profile_form.is_valid():
    user_profile_form.save()
else
    # do other stuff

我猜你需要写一些代码。这将是一个很好的开始。我已经做到了这一点。这是一个非常普通的问题,也许你可以将你的代码粘贴到这里,并指出你缺少的部分。请仔细看看我的OP,我已经修改了它。这是一个问题,Django 1.5上的定制用户模型功能应该几乎可以解决。感谢您的及时回复,请查看上面编辑的版本。我已经按照你的建议做了,但是获取错误用户名已经存在,但是当我指定一个新用户名时,它会更新,虽然它不会更新用户名,但会更新其他字段。
@login_required
def editprofile(request):
    registeredmember = request.user.get_profile()
    if request.method == 'POST':
        userprofile_edit = RegistrationForm(request.POST, instance = registeredmember)
        if userprofile_edit.is_valid():
            userprofile_edit.save()
            return HttpResponseRedirect('/profile/')
    else:
        userprofile_edit = RegistrationForm(instance = registeredmember)
    return render_to_response('carloan/editprofile.html', {'userprofile_edit': userprofile_edit}, context_instance=RequestContext(request))
class EditForm(forms.ModelForm):
    class Meta:
        model = Registeredmember
        exclude = ('user','username','email','password','password1',)
@login_required
def editprofile(request):
    if request.method == 'POST':
        userprofile_edit = EditForm(request.POST, instance = request.user.get_profile())
        if userprofile_edit.is_valid():
            userprofile_edit.save()
            return HttpResponseRedirect('/profile/')
    else:
        userprofile_edit = EditForm(instance = request.user.get_profile())
    return render_to_response('carloan/editprofile.html', {'userprofile_edit': userprofile_edit}, context_instance=RequestContext(request))
user_profile_form = RegistrationForm(request.POST, instance=request.user.get_profile())
if user_profile_form.is_valid():
    user_profile_form.save()
else
    # do other stuff