Django update already existing user information -
ok have registration working users enter username, email, first/last name.
my question how give user ability edit email, first/last names?
thanks!
there nothing special default django user. in fact, django auth application normal django application has own models, views, urls , templates other app write.
to update model instance - can use generic updateview
, works this:
- you create template show form used update model.
- you can (optionally) create own form class used - not required.
- you pass model updated along instance view.
- the view takes care of rest of logic.
here how implement in practice. in views.py
:
from django.views.generic.edit import updateview django.core.urlresolvers import reverse_lazy django.contrib.auth.models import user class profileupdate(updateview): model = user template_name = 'user_update.html' success_url = reverse_lazy('home') # user # redirected once form # filled in def get_object(self, queryset=none): '''this method load object used load form edited''' return self.request.user
the user_update.html
template simple:
<form method="post"> {% csrf_token %} {{ form }} <input type="submit" /> </form>
all that's left wiring in urls.py
:
from .views import profileupdate urlpatterns = patterns('', # other url maps url(r'^profile/', profileupdate.as_view(), name='profile'), )
Comments
Post a Comment