forms - Editing users in Django -
i trying to edit user using form used create user, have no idea why i'm getting error user username exists.
here view:
def registration_edit(request): """ registration step2: user should authenticated reach step. authentication provided first step or user login. """ if request.user.is_authenticated(): if request.post: form = registrationform(request.post or none, instance=request.user) if form.is_valid(): form.save() return httpresponseredirect(reverse('reg_step_2')) else: form = registrationform(instance=request.user) page = 'account' title = 'editing user registration' context = {'title': title, 'form': form, 'page': page} template = 'customer/registration.djhtml' return render_to_response(template, context, context_instance=requestcontext(request)) else: messages.info(request, '<strong>note</strong>: must logged in edit account.') return httpresponseredirect('/')
forms.py did form because want include firstname , lastname field included on registration.
django import forms django.contrib.auth.models import user django.contrib.auth.forms import usercreationform class registrationform(usercreationform): class meta: model = user exclude = ('is_staff', 'is_active', 'is_superuser', 'last_login', 'date_joined', 'groups', 'user_permissions', 'password')
and here template
<form class="form-horizontal" action='.' method="post"> {% csrf_token %} <fieldset> <div id="legend"> <legend class=""> {{ title|title }} </legend> </div> {% f in form %} <div class="control-group"> <label class="control-label" for="username">{{ f.label }}</label> <div class="controls"> {{ f }} <i style="color: orange">{{ f.errors|striptags }}</i> </div> </div> {% endfor %} <div class="controls"> <button class="btn btn-success"> continue </button> </div> </fieldset> </form>
anyone tell me messing around here? appreciated.
your inherits usercreationform cleans username field.
in case see userchangeform instead.
Comments
Post a Comment