Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form>
- <fieldset class='text-center'>
- <legend>Create your Account</legend>
- <div>
- <form action="" method="post" enctype="multipart/form-data">
- {% csrf_token%}
- {% include 'registration/form-template.html' %}
- <div class="form-group">
- <div align="center" >
- <input type="submit" class="btn btn-success" value="submit"/>
- <input type="hidden" name="next" value="{{ next }}" />
- </div>
- </div>
- </form>
- </div>
- <br>
- <a href="forgot_password.html">Forgot password?</a>
- </fieldset>
- </form>
- {% for field in form %}
- <div class="form-group">
- <div class="col-som-offset-2 col-som-10">
- <span class="text-danger small">{{ field.errors }}</span>
- </div>
- <label >{{ field.label_tag }}{{ field }}</label>
- </div>
- {% endfor %}
- from django.conf.urls import url
- from . import views
- from django.contrib.auth import views as auth_views
- app_name = 'registration'
- urlpatterns = [
- url(r'^$', views.IndexView.as_view(), name='registration'),
- url(r'^customer/add/$', views.UserFormView.as_view(), name='customer-add'),
- ]
- from django.conf import settings
- from django.contrib.auth import urls
- from django.conf.urls.static import static
- from django.conf.urls import include, url
- from django.contrib import admin
- urlpatterns = [
- url(r'^admin/', admin.site.urls),
- url(r'', include('registration.urls')),
- url(r'^accounts/', include('django.contrib.auth.urls'))
- ]
- from django.views import generic
- from .models import customers
- from django.views.generic.edit import CreateView, UpdateView, DeleteView
- from django.shortcuts import render, redirect
- from django.contrib.auth import authenticate, login
- from django.views import View
- from .forms import UserForm
- from django.contrib.auth.decorators import login_required
- class IndexView(generic.ListView):
- template_name = 'registration/home.html'
- def get_queryset(self):
- return customers.objects.all()
- class UserFormView(View):
- form_class = UserForm
- template_name = 'registration/customers_form.html'
- # display blank form
- def get(self, request):
- form = self.form_class(None)
- return render(request, self.template_name, {'form': form})
- # process form data
- def post(self,request):
- form = self.form_class(request.POST)
- if form.is_valid():
- user = form.save(commit=False)
- username = form.cleaned_data['username']
- password = form.cleaned_data['password']
- user.set_password(password)
- user.save()
- # return username if credentials are correct
- user = authenticate(username=username, password=password)
- if user is not None:
- if user.is_active:
- login(request, user)
- return redirect('registration:index')
- return render(request, self.template_name, {'form': form})
- from django import forms
- from django.contrib.auth.models import User
- from django.forms import ModelForm
- class UserForm(forms.ModelForm):
- password = forms.CharField(widget=forms.PasswordInput)
- class Meta:
- model = User
- fields = [
- 'username',
- 'email',
- 'password',
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement