python - How to customize UserRegistration Form of Django? -
i want know how change display of default userregistrationform. views.py file.
from django.http import * django.shortcuts import render_to_response django.http import httpresponseredirect django.contrib import auth django.core.context_processors import csrf django.contrib.auth.forms import usercreationform forms import myregistrationform def register_user(request): if request.method == 'post': form = myregistrationform(request.post) if form.is_valid(): form.save() return httpresponseredirect('/accounts/register_success') args = {} args.update(csrf(request)) args['form'] = myregistrationform() return render_to_response('register.html', args) def register_success(request): return render_to_response('register_success.html')
this displayed in templates of register_user.
{% extends "application/base.html" %} {% block content %} <h2> register </h2> <form action="/accounts/register/" method="post">{% csrf_token %} {{form}} <input type="submit" value="register" /> </form> {% endblock %}
i want access each , every filed of {{form}} independently easy access view.how it??
also forms.py file
from django import forms django.contrib.auth.models import user django.contrib.auth.forms import usercreationform class myregistrationform(usercreationform): email = forms.emailfield(required=true) class meta: model = user fields = ('username', 'email', 'password1', 'password2') def save(self,commit=true): user=super(myregistrationform, self).save(commit=false) user.email=self.cleaned_data['email'] if commit: user.save() return user
please me new django??
you can following:
- create
appname/templates/registration
-folder - in folder, put html-templates want have (e.g. login.html, password_change_form.html, ...). might idea take @ original forms in
django/contrib/admin/templates/registration (or ../admin)
-folder idea of what's done in original templates. - customize templates needs. if want apply ssame css every page, suggest writing own base.html , extend using
{% extends "base.html" %}
. add views
urls.py
, eg.g.:url(r'^accounts/login/$', 'django.contrib.auth.views.login'), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout_then_login'), url(r'^accounts/password_change_done/$', 'django.contrib.auth.views.password_change_done', name="password_change_done"), url(r'^accounts/password_change/$', 'django.contrib.auth.views.password_change', name='password_change'),
there no need define in forms.py or views.py.
Comments
Post a Comment