This is my views.py from django.views import generic from django.views.generic import ListView from django.views.generic import DetailView,UpdateView,DeleteView from django.views.generic import CreateView from django.shortcuts import render,redirect from django.contrib.auth import authenticate,login from django.views.generic import View from .models import Album, Song from .forms import UserForm
class IndexView(ListView): template_name="music/index.html" context_object_name='all_Albums' def get_queryset(self): return Album.objects.all() class DetailView(DetailView): model=Album template_name="music/detail.html" class AlbumCreate(CreateView): model=Album fields=['artist','album_title','genre','album_logo'] class UserFormView(View): form_class=UserForm template_name='music/registration_form.html' #display blank form def get(self , request): form=self.form_class(None) return render(request,self.template_name,{'form':form}) #process from data def post(self, request): form=self.form_class(request.POST) if form.is_valid(): user=form.save(commit=False) #cleaned (normalized) data username=form.cleaned_data['username'] password=form.cleaned_data['password'] user.set_password(password) user.save() #returns User objects if credentials are correct user=authenticate(username=username,password=password) if user is not None: if user.is_active: login(request,user) return redirect('music:index') return render(request,self.template_name,{'form':form}) On Tuesday, June 25, 2019 at 9:37:34 PM UTC+5:30, Sipum wrote: > > Plz share views.py as well.. I hvae mentioned two. Kindly share. > > On Tue, 25 Jun, 2019, 8:47 PM Harshit, <agarwalh...@gmail.com > <javascript:>> wrote: > >> Here is urls.py of my app >> >> from django.urls import path >> from . import views >> from django.conf import settings >> from django.conf.urls.static import static >> >> app_name="music" >> >> urlpatterns=[ >> #/music/ >> path('',views.IndexView.as_view(),name='index'), >> >> path('register/',views.UserFormView.as_view(),name='register'), >> >> path('<pk>/',views.DetailView.as_view(),name='detail'), >> >> path('album/add/',views.AlbumCreate.as_view(),name='album-add'), >> ] >> urlpatterns += static(settings.MEDIA_URL, document_root >> =settings.MEDIA_ROOT) >> >> Here is my main urls.py >> from django.contrib import admin >> from django.urls import path,include >> from . import settings >> from django.contrib.staticfiles.urls import static >> from django.contrib.staticfiles.urls import staticfiles_urlpatterns >> >> urlpatterns = [ >> path('',include('music.urls')), >> path('music/',include('music.urls')), >> path('admin/', admin.site.urls), >> ] >> urlpatterns += staticfiles_urlpatterns() >> urlpatterns += static(settings.MEDIA_URL, document_root >> =settings.MEDIA_ROOT) >> >> On Tuesday, June 25, 2019 at 4:14:05 PM UTC+5:30, Sipum wrote: >>> >>> Can u plz attach your urls.py as functions associated in views.py >>> >>> Thanks. >>> >>> On Mon, 24 Jun, 2019, 8:08 PM Harshit Agarwal, <agarwalh...@gmail.com> >>> wrote: >>> >>>> Hi guys, >>>> I am currently working on a working on a project. Everything is working >>>> fine but i am not able to access my admin. How can i solve this? >>>> Here is my Stack Trace >>>> Traceback: >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\core\handlers\exception.py" >>>> >>>> in inner >>>> 34. response = get_response(request) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\core\handlers\base.py" >>>> in _get_response >>>> 126. response = >>>> self.process_exception_by_middleware(e, request) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\core\handlers\base.py" >>>> in _get_response >>>> 124. response = wrapped_callback(request, >>>> *callback_args, **callback_kwargs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\views\generic\base.py" >>>> in view >>>> 68. return self.dispatch(request, *args, **kwargs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\views\generic\base.py" >>>> in dispatch >>>> 88. return handler(request, *args, **kwargs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\views\generic\detail.py" >>>> >>>> in get >>>> 106. self.object = self.get_object() >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\views\generic\detail.py" >>>> >>>> in get_object >>>> 36. queryset = queryset.filter(pk=pk) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\query.py" in >>>> filter >>>> 844. return self._filter_or_exclude(False, *args, **kwargs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\query.py" in >>>> _filter_or_exclude >>>> 862. clone.query.add_q(Q(*args, **kwargs)) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\sql\query.py" >>>> in add_q >>>> 1263. clause, _ = self._add_q(q_object, self.used_aliases) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\sql\query.py" >>>> in _add_q >>>> 1287. split_subq=split_subq, >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\sql\query.py" >>>> in build_filter >>>> 1225. condition = self.build_lookup(lookups, col, value) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\sql\query.py" >>>> in build_lookup >>>> 1096. lookup = lookup_class(lhs, rhs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\lookups.py" >>>> in >>>> __init__ >>>> 20. self.rhs = self.get_prep_lookup() >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\lookups.py" >>>> in >>>> get_prep_lookup >>>> 70. return self.lhs.output_field.get_prep_value(self.rhs) >>>> >>>> File >>>> "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\fields\__init__.py" >>>> >>>> in get_prep_value >>>> 965. return int(value) >>>> >>>> Exception Type: ValueError at /admin/ >>>> Exception Value: invalid literal for int() with base 10: 'admin' >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Django users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to django...@googlegroups.com. >>>> To post to this group, send email to django...@googlegroups.com. >>>> Visit this group at https://groups.google.com/group/django-users. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-users/CAE%2BC-X-o7sW8m2-DMx4R5CnGrYbYS%2B%2Bx_cYi-BL%3DHwK_b%2BdrHg%40mail.gmail.com >>>> >>>> <https://groups.google.com/d/msgid/django-users/CAE%2BC-X-o7sW8m2-DMx4R5CnGrYbYS%2B%2Bx_cYi-BL%3DHwK_b%2BdrHg%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django...@googlegroups.com <javascript:>. >> To post to this group, send email to django...@googlegroups.com >> <javascript:>. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/15dbe92c-6344-4ca4-aa18-742610627b03%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/15dbe92c-6344-4ca4-aa18-742610627b03%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f8365b76-5004-4c11-b357-a6c838b74339%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.