daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. url(r'^$', views.IndexView.as_view(), name='index'),
  2. url(r'^sign_up/$', views.UserFormView.as_view(), name='sign_up'),
  3. url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
  4. url(r'^album/add/$', views.AlbumCreate.as_view(), name='album-add'),
  5. url(r'^(?P<pk>[0-9]+)/$', views.AlbumUpdate.as_view(), name='album-update'),
  6. url(r'^(?P<pk>[0-9]+)/delete/$', views.AlbumDelete.as_view(), name='album-delete'),
  7. url(r'^login/$', views.Login.as_view(), name='login'),
  8.    
  9. from django.views.generic.edit import CreateView,UpdateView,DeleteView
  10.    
  11. def get_queryset(self):
  12.     return Album.objects.all()
  13.    
  14. def get(self, request):
  15.     form = self.form_class(None)
  16.     return render(request, self.template_name, {'form':form})
  17.  
  18. def post(self,request):
  19.     form = self.form_class (request.POST)
  20.  
  21.     if form.is_valid():
  22.  
  23.         user= form.save(commit=False)
  24.  
  25.         username = form.cleaned_data['username']
  26.         password = form.cleaned_data['password']
  27.         user.set_password(password)
  28.         user.save()
  29.  
  30.         user = authenticate(username=username,password=password)
  31.  
  32.         if user is not None:
  33.             if user.is_active:
  34.                 login(request, user)
  35.                 return redirect('music:index')
  36.     return render (request, self.template_name, {'form': form})
  37.    
  38. def get(self, request):
  39.     form = self.form_class(None)
  40.     return render(request, self.template_name, {'form':form})
  41.  
  42. def post(self, request):
  43.     form = self.form_class (request.POST)
  44.  
  45.     if form.is_valid():
  46.         user = form.save (commit=False)
  47.         user.save ()
  48.         username = ['username']
  49.         password = ['password']
  50.         user = authenticate(username=username,password=password)
  51.  
  52.         if user is not None:
  53.             if user.is_active:
  54.                 login(request, user)
  55.                 return redirect('music:index')
  56.     return render (request, self.template_name, {'form': form}
  57.  
  58. {% for field in form %}
  59. <div class="form-group">
  60.     <div class="col-sm-offset-2 col-sm-10">
  61.         <span class="text-danger small">{{ field.error }}</span>
  62.     </div>
  63.     <label class="control-label col-sm-2">{{ field.label_tag }}</label>
  64.     <div class="col-sm-10">{{ field }}</div>
  65. </div>
  66.    
  67. from django.contrib.auth.models import User
  68.    
  69. class Meta:
  70.     model = User
  71.     fields = ['username','email','password']
RAW Paste Data
Top