No Reverse Match Error, When creating a new user (new user application) it should direct back to home (to the core application)

31 views
Skip to first unread message

Ahmed Khairy

unread,
Apr 19, 2020, 12:36:05 AM4/19/20
to Django users
For this project, I have made 2 applications: Core and Users

Creating a new user is the 2nd application.
I am trying to direct the new user after registration to 'home'

I keep getting NoReverse Match Error

This is the view.py this is the code:

def register(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            messages.success(
                request, f'Account created for {username}! Show us your Designs')
        return redirect('home')
    else:
        form = UserCreationForm()
    return render(request, 'register.html', {'form': form})

This is the url.py in the core application: 

urlpatterns = [
    path('', HomeView.as_view(), name='home'),
    path('checkout/', checkout, name='checkout'),
    path('product/<slug>/', ItemDetailView.as_view(), name='product'),
    path('score/', PostListView.as_view(), name='score'),
    path('register/', user_views.register, name='register'),
]


What do I need to do to fix this issue, 

Thank you all in advance
NoReverseMatch.jpg

Motaz Hejaze

unread,
Apr 19, 2020, 2:09:42 AM4/19/20
to Django users
اعمل اسم الفانكشن الحقيقي مكان اسم ال url او استخدم redirect reverse

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4584668f-3cf5-40fe-930c-69c75b74b23d%40googlegroups.com.

Jorge Gimeno

unread,
Apr 19, 2020, 10:50:36 AM4/19/20
to django...@googlegroups.com
I would try to replace return redirect('home') with return
redirect(reverse('home'))

-Jorge
>> <https://groups.google.com/d/msgid/django-users/4584668f-3cf5-40fe-930c-69c75b74b23d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHV4E-eymYMWLhd23iEN%2BJqMMkdLNrA9OxHq41x8EuRrj0bh2Q%40mail.gmail.com.
>

Farai M

unread,
Apr 19, 2020, 12:31:00 PM4/19/20
to django...@googlegroups.com
You can use Httpresponse(reverse_lazy('appname'))

--
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...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages