i tried class base view in my blog website authorlogin.every time i logged in though my author get logged,but get a page of error.i have just converst login into classbased view but my authorprofile is function based view
the error message:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/profile/
Using the URLconf defined in blog.urls, Django tried these URL patterns, in this order:
admin/
author/
catagory/
post/
[name=’base’]
The current path, accounts/profile/, didn’t match any of these.
main urls.py
urlpatterns = [
path('author/',include('author.urls')),
]
authorlogin url
urlpatterns = [
path('author.login/',views.authorlogin.as_view(),name='login'),
path('profile',views.authorprofile,name='profile')
]
views.py
class authorlogin(LoginView):
template_name='login.html'
def form_valid(self, form):
messages.success(self.request,'Welcome mr.{name}')
return super().form_valid(form)
def form_invalid(self, form):
messages.success(self.request,'Logged in information incorrect')
return super().form_invalid(form)
def get_context_data(self, **kwargs) :
context=super().get_context_data(**kwargs)
context['type']='login'
return context
@login_required
def authorprofile(request):
if request.user.is_authenticated:
data=Post.objects.filter(author=request.user)
return render (request,'profile.html',{'data':data})
else:
return redirect('login')
i tried that after get login it take me directly to profile page not an error page
Abrar Rofique is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.