Reputation: 365
I am getting the above error when i tried to redirect from my UserAuth app to UserArea app. It says 'NoReverseMatch at /index/'.
UserAuth/views.py
def loginUser(request):
if request.method == "POST":
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
# return render(request, 'home.html')
return redirect('nsUserArea:urlUserHome')
else:
messages.info(request, 'User name or password is incorrect')
return render(request, "Login.html")
USerAuth/urls.py
urlpatterns = [
path('', views.loginUser, name="urllogin"),
path('logout/', views.logoutUser, name="urllogout"),
path('register/', views.register, name="urlregister"),
path('home/', views.home, name="urlhome"),
]
UserArea/urls.py
urlpatterns = [
path('', views.IndexPage, name="urlUserHome"),
]
My main project urls.py file is this:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('UserAuth.urls', namespace="nsUserAuth")),
path('index/', include('UserArea.urls', namespace="nsUserArea")),
]
UserArea/views.py
def IndexPage(request):
return redirect(request, 'home.html')
home.html
<h1>Home</h1>
Upvotes: 0
Views: 1604
Reputation: 1
def IndexPage(request):
return redirect(request, 'home.html')
Try without request
def IndexPage(request):
return redirect('home.html')
Upvotes: 0
Reputation: 69
I was also getting the same problem that you are getting:
I modified my redirect
to render
.
Change
return redirect()
to
return render()
Upvotes: 2