Reputation: 193
I want to know how to change the display of default UserRegistrationForm. This is my views.py file.
from django.http import *
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.core.context_processors import csrf
from django.contrib.auth.forms import UserCreationForm
from 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 is what is 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 to access each and every filed of the {{form}} independently so that the it is easy to access the view.how to do it??
Also this is my forms.py file
from django import forms
from django.contrib.auth.models import User
from 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 Help me i am new to django??
Upvotes: 0
Views: 4283
Reputation: 5167
You can do the following:
appname/templates/registration
-folderdjango/contrib/admin/templates/registration (or ../admin)
-folder to get an idea of what's done in the original templates.{% extends "base.html" %}
. Add the views to your 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 is no need to define anything in forms.py or views.py.
Upvotes: 3
Reputation: 3734
So make your own form:
From Django-x.x/django/contrib/admin/templates
copy base.html, base_site.html and login.html
to project_name/templates/admin
Then change the files as necessary.
Upvotes: 1