0
votes

Though both links are exactly the same, I keep receiving a "Page Not Found at /accounts/login/next?" error whenever I click my link. What's the error in my code? 'explore' works, but 'happening' doesn't! Please help!

views.py

def explore(request):
    return render(request, 'explore.html')

def happening(request):
    return render(request, 'happening.html')

html template

  <div id="happening_log">
     <a style= "padding-left:5px" href="{% url 'happening' 
          %}">Happening</a>
  </div>

urls.py

urlpatterns = [
     path('', views.explore, name='explore'),
     path('<user__name>/', views.home, name='home'),
     path('happening/', views.happening, name='happening'),
]

Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/accounts/login/?next=/happening/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

admin/
[name='explore']
<user__name>/ [name='home']
/happening/ [name='happening']
users/
^static\/(?P<path>.*)$
^media\/(?P<path>.*)$
The current path, accounts/login/, didn't match any of these.
1
It seems like you're being redirected to login but you don't have those urls enabled? Did you paste here the entire views.py? - bonidjukic
Do you have a login_required decorator or something in your views? there must be a reason why you're being redirected to log in. Is that what you want? - Sergio
could you add the urls.py file from project level - dxt
You have been redirecting to your login page, but your login url is not defined. - Bidhan Majhi

1 Answers

0
votes

Did you make a registration/login.html file in your project site? The url, http://127.0.0.1:8000/accounts/login/?next=/happening/ is accessing login template, so you have to make a default registration/login.html or another login like like below;

def login(request):

    if request.method == 'POST':
        form = LoginForm(request.POST)

        if form.is_valid():
            username=form.cleaned_data.get('username')
            password=form.cleaned_data.get('password')
            user = authenticate(username=username, password=password)

            if user and user.profile.status == 'WORKING':
                auth.login(request, user)

                if user.profile.passwd:
                    return redirect('myprofile')
                else:
                    return redirect('password')
    else:
        form = LoginForm()

    return render(request, 'accounts/login.html', {'form': form})