Generic detail view UserRegister must be called with either an object pk or a slug in the URLconf

I'm getting this error when trying to register to my to-do list web
Generic detail view UserRegister must be called with either an object pk or a slug in the URLconf.

class UserRegister(CreateView):
    model = User
    form_class = UserRegisterForm
    template_name = 'users/form_register.html'
    redirect_authenticated_user = True
    success_url = reverse_lazy('tasks')

    # Forbid logged in user to enter register page
    def get(self, *args, **kwargs):
        if self.request.user.is_authenticated:
            return redirect('tasks')
        return super(UserRegister, self).get(*args, **kwargs)

    # Send email verification
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            user =
            user.is_active = False

            current_site = get_current_site(request)
            subject = 'Activate your account'
            message = render_to_string('users/account_activation_email.html', {
                'user': user,
                'domain': current_site.domain,
                'uid': urlsafe_base64_encode(force_bytes(,
                'token': account_activation_token.make_token(user),
            user.email_user(subject, message)
            return redirect('login')
            return self.form_invalid(form)

urlpatterns = [
    path('register/', UserRegister.as_view(), name='register'),
    path('login/', UserLogin.as_view(), name='login'),
    path('logout/', LogoutView.as_view(next_page='login'), name='logout'),
    path('activate/<uidb64>/<token>/', ActivateAccount.as_view(), name='activate'),

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)

Maybe it got something to do with the But to be honest I don't really know what else to put there.

Keep in mind I have two apps, the user app for registration and login and whatnot, and the tasks app for displaying tasks, creating, deleting task, etc.

Back to Top