rajiv
rajiv

Reputation: 89

Django : Navigation rerouting to wrong page

I have been following this link

https://www.youtube.com/watch?v=p_n7g6tVloU&list=PLw02n0FEB3E3VSHjyYMcFadtQORvl1Ssj&index=8

I am facing a issue with my code the code is supposed to direct me to login.html but it is navigating me back to home.html

the link from accounts/urls.py is supposed to direct me to login.html but but is navigate me back to home

The codes that i have been working are

accounts/urls.py

urlpatterns= [
    url('',views.home),
    url(r'^login/$', login, {'template_name' : 'accounts/login.html'}),
]

the root tutorials path = tutorials/urls.py

urlpatterns = [
path(r'^admin/', admin.site.urls),
re_path(r'^account/',  include('accounts.urls'))
]

views.py

def home(request):
numbers = [1,2,3,4,5]
name = "Rajiv Pai"

args = {'myName' : name, 'numbers' : numbers}
return render(request,'accounts/home.html', args)

accounts/home.html

{% extends 'base.html' %}
<h1> Home Page</h1>
<!DOCTYPE html>
<html>
<head>
    {% block head %}
    <title> This is Home Page</title>
    {% endblock %}
</head>
<body>
    {% block body%}
    <h1> Hello World</h1>
    {% endblock %}
</body>
</html>

login.html

<!DOCTYPE html>
<html>
<head>
    {% load static %}
    <link rel="stylesheet" type="text/css" href="{% static 'accounts/style.css' %}">
<title>Login</title>
</head>
<body>
    <div class = "container">
    <h1>Welcome</h1> You can login here!!!
    <button class = "btn btn-danger outline" type = "button" name = "button">Click Here</button>
    <h1>Hello, {{myName}} </h1>
    <br/>
    <ul>
    {% for number in numbers %}
    <li>{{ number }}</li>
    {% endfor %}
    </ul>
</div>
</body>
</html>

Upvotes: 0

Views: 75

Answers (1)

gagan trivedi
gagan trivedi

Reputation: 434

the problem is in your urls.py

urlpatterns= [ url('',views.home), url(r'^login/$', login, {'template_name' : 'accounts/login.html'}), ]

your first url pattern is wrong thats why its redirecting to home instead of login

urlpatterns= [
url('^$',views.home),
url(r'^login/$', login, {'template_name' : 'accounts/login.html'}),

]

to redirect to login you can use above code snippet

Upvotes: 1

Related Questions