【发布时间】:2018-08-18 12:55:34
【问题描述】:
我一直在关注这个链接
https://www.youtube.com/watch?v=p_n7g6tVloU&list=PLw02n0FEB3E3VSHjyYMcFadtQORvl1Ssj&index=8
我的代码遇到问题该代码应该将我引导到 login.html 但它正在将我导航回 home.html
accounts/urls.py 中的链接应该将我引导至 login.html,但将我导航回主页
我一直在工作的代码是
accounts/urls.py
urlpatterns= [
url('',views.home),
url(r'^login/$', login, {'template_name' : 'accounts/login.html'}),
]
根教程路径 = 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>
登录.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>
【问题讨论】:
-
您认为应该将哪个代码“引导至 login.html”?您如何逐步诊断问题?您尝试打开哪个链接?
标签: python django django-templates