使用django注销时出现NoReverseMatch错误
我正在成功登录,但是,在注销时,我面临以下错误。你能帮我一下吗?然而,早些时候,当我开始用新功能扩展我的应用程序时,出现了这个错误。我是django的新手,请告诉我,我哪里做错了使用django注销时出现NoReverseMatch错误,django,Django,我正在成功登录,但是,在注销时,我面临以下错误。你能帮我一下吗?然而,早些时候,当我开始用新功能扩展我的应用程序时,出现了这个错误。我是django的新手,请告诉我,我哪里做错了 Reverse for 'home' with arguments '(<WSGIRequest: GET '/blog/logout'>,)' and keyword arguments '{}' not found. 0 pattern(s) tried: [] 和home.html,它在注销后重定向
Reverse for 'home' with arguments '(<WSGIRequest: GET '/blog/logout'>,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
和home.html,它在注销后重定向到的位置
{% load staticfiles %}
{%load comments%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Sourav's blog</title>
<!-- Bootstrap Core CSS -->
{%block styling%}
<link href="{%static 'css/bootstrap.min.css'%}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{%static 'css/blog-post.css'%}" rel="stylesheet">
{%endblock styling%}
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Ideate</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="{%url 'blog_new_post'%}">New idea</a>
</li>
<!-- <li><a href="{%url 'blog_login'%}">Login</a></li> -->
{{user.is_authenticated}}
{% if user.is_authenticated %}
<li>
<a href="{%url 'blog_logout'%}">Logout</a>
</li>
{% else %}
<li>
<a href="{%url 'blog_login'%}">Login</a>
</li>
{% endif %}
<li>
<a href="#">Help</a>
</li>
{% if user.is_authenticated %}
<li>
<a href="#">Hi {{user.username}}</a>
</li>
{%else%}
{% endif %}
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Post Content Column -->
<div class="col-lg-8">
<!-- Blog Post -->
<!-- Title -->
<h1>Idea Blog</h1>
<!-- Author -->
<p class="lead">
by <a href="#">Sourav</a>
</p>
<hr>
<!-- Date/Time -->
<p><span class="glyphicon glyphicon-time"></span>
Posted on
<!-- {%for i in blog_data%}
{{i.posted_on}}
{%endfor%}</p> -->
{{last_element.posted_on}}
<hr>
<!-- Preview Image -->
<img class="img-responsive" src="http://placehold.it/900x300" alt="">
<hr>
<!-- Post Content -->
<!-- <p>Below is the result</p> -->
<!-- <p>{{blog_data}}</p> -->
<p>
<!-- {%for i in blog_data%}
<h1>{{i.title}}</h1>
<p>{{i.description}}</p>
{%empty%}
<span>No data</span>
{%endfor%} -->
<!-- {{last_element}} -->
<h1>{{last_element.title}}</h1><span> posted by {{last_element.posted_by}}</span>
<p>Description : {{last_element.description}}</p>
{{last_element.image}}
<p>Tags : {{last_element.tags}}</p>
{% get_comment_count for blog.blogpost last_element.id as comment_count %}
<p>{{ comment_count }} comments have been posted.</p>
{% get_comment_list for blog.blogpost 1 as comment_list %}
{% for comment in comment_list %}
<p>Posted by: {{ comment.user_name }} on {{ comment.submit_date }}</p>
<p>Comment: {{ comment.comment }}</p>
{% endfor %}
{% get_comment_form for blog.blogpost last_element.id as form %}
<!-- A context variable called form is created with the necessary hidden
fields, timestamps and security hashes -->
<table>
<form action="{% comment_form_target %}" method="post">
{% csrf_token %}
{{ form }}
<tr>
<td colspan="1">
<input type="submit" name="submit" value="Post">
<input type="submit" name="preview" value="Preview">
<input type="hidden" name="next" value="{% url 'comment_posted' %}" />
</td>
</tr>
</form>
</table>
{% get_comment_list for blog.blogpost last_element.id as comment_list %}
{%for comment in comment_list%}
<li><b>{{comment.name}}</b> has posted comment on {{comment.submit_date}} </li>
<ul><li>{{comment.comment}}</li></ul>
<a name="c{{ comment.id }}"></a>
<a href="{% get_comment_permalink comment %}">
see comment details
</a>
{%endfor%}
</p>
</div>
<div class="col-md-4">
<!-- Blog Search Well -->
<form action = "{%url 'blog_search'%}" method = "POST">
<div class="well">
<h4>Blog Search</h4>
<div class="input-group">
{%csrf_token%}
<input type="text" class="form-control" name = "keyword", placeholder = "Enter search keyword">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<!-- /.input-group -->
</div>
</form>
<!-- Blog Categories Well -->
<div class="well">
<h4>Tags</h4>
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled">
<!-- {%for a in tags_list%}
<a href="">{{a}}</a>
{%endfor%} -->
<!-- {%for a in tags_list%}
<a href="">{{a}}</a>
{%endfor%} -->
{%for a in tags_list%}
<form id = 'form1' action = "{%url 'tag_search'%}" method = "POST">
{%csrf_token%}
<!-- <a href = "" name = 'tag'>{{a}},</a> -->
<!-- <a href="javascript:;" onclick="document.getElementById('form1').submit();" name = 'tag'>{{a}},</a> -->
<input type = 'submit' id = 'mybuttonlink' value = {{a}} name = 'tag'>
</form>
{%endfor%}
<!-- {%for a in tags_list%}
<a href="{%url 'tag_search'%}">{{a}}</a>
{%endfor%} -->
<!-- <li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li> -->
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled">
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
</ul>
</div>
</div>
<!-- /.row -->
</div>
<!-- Side Widget Well -->
<div class="well">
<h4>Side Widget Well</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, perspiciatis adipisci accusamus laudantium odit aliquam repellat tempore quos aspernatur vero.</p>
</div>
</div>
</div>
</div>
</div>
<!-- Blog Sidebar Widgets Column -->
<!-- /.row -->
<hr>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © Your Website 2014</p>
</div>
</div>
<!-- /.row -->
</footer>
</div>
<!-- /.container -->
<!-- jQuery -->
{%block javascript%}
<script src="{%static 'js/jquery.js'%}"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{%static 'js/bootstrap.min.js'%}"></script>
{%endblock javascript%}
</body>
</html>
{%load staticfiles%}
{%loadcomments%}
苏拉夫的博客
{%块样式%}
{%endblock样式%}
切换导航
-
{{user.is_authenticated}
{%if user.u经过身份验证%}
-
{%else%}
-
{%endif%}
-
{%if user.u经过身份验证%}
-
{%else%}
{%endif%}
创意博客
通过
张贴在
{{last_element.posted_on}}
{{last_element.title}}由{{last_element.posted_by}发布
描述:{last_element.Description}}
{{last_element.image}
标记:{last_element.Tags}
{%get_comment_count for blog.blogpost last_element.id as comment_count%}
{{comment\u count}}评论已经发布。
{%get_comment_list for blog.blogpost 1 as comment_list%}
{注释列表%中的注释为%0}
发布人:{{comment.user_name}}在{{comment.submit_date}上发布
注释:{{Comment.Comment}}
{%endfor%}
{%get_comment_form for blog.blogpost last_element.id as form%}
{%csrf_令牌%}
{{form}}
{%get_comment_list for blog.blogpost last_element.id as comment_list%}
{注释列表%中的注释为%0}
{{comment.name}已在{{comment.submit_date}上发布了评论
- {{comment.comment}
{%endfor%}
博客搜索
{%csrf_令牌%}
标签
{标记中的%u列表%}
{%csrf_令牌%}
{%endfor%}
-
-
-
-
侧井
Lorem ipsum dolor sit amet,奉献精英。发明人,是一位名叫阿迪皮斯·阿迪皮斯·库萨姆斯·劳丹提姆·阿迪奎姆·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪皮斯·阿迪姆·阿迪奎姆·阿
版权及副本;您的网站2014
{% load staticfiles %}
{%load comments%}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Sourav's blog</title>
<!-- Bootstrap Core CSS -->
{%block styling%}
<link href="{%static 'css/bootstrap.min.css'%}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{%static 'css/blog-post.css'%}" rel="stylesheet">
{%endblock styling%}
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Ideate</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li>
<a href="{%url 'blog_new_post'%}">New idea</a>
</li>
<!-- <li><a href="{%url 'blog_login'%}">Login</a></li> -->
{{user.is_authenticated}}
{% if user.is_authenticated %}
<li>
<a href="{%url 'blog_logout'%}">Logout</a>
</li>
{% else %}
<li>
<a href="{%url 'blog_login'%}">Login</a>
</li>
{% endif %}
<li>
<a href="#">Help</a>
</li>
{% if user.is_authenticated %}
<li>
<a href="#">Hi {{user.username}}</a>
</li>
{%else%}
{% endif %}
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Post Content Column -->
<div class="col-lg-8">
<!-- Blog Post -->
<!-- Title -->
<h1>Idea Blog</h1>
<!-- Author -->
<p class="lead">
by <a href="#">Sourav</a>
</p>
<hr>
<!-- Date/Time -->
<p><span class="glyphicon glyphicon-time"></span>
Posted on
<!-- {%for i in blog_data%}
{{i.posted_on}}
{%endfor%}</p> -->
{{last_element.posted_on}}
<hr>
<!-- Preview Image -->
<img class="img-responsive" src="http://placehold.it/900x300" alt="">
<hr>
<!-- Post Content -->
<!-- <p>Below is the result</p> -->
<!-- <p>{{blog_data}}</p> -->
<p>
<!-- {%for i in blog_data%}
<h1>{{i.title}}</h1>
<p>{{i.description}}</p>
{%empty%}
<span>No data</span>
{%endfor%} -->
<!-- {{last_element}} -->
<h1>{{last_element.title}}</h1><span> posted by {{last_element.posted_by}}</span>
<p>Description : {{last_element.description}}</p>
{{last_element.image}}
<p>Tags : {{last_element.tags}}</p>
{% get_comment_count for blog.blogpost last_element.id as comment_count %}
<p>{{ comment_count }} comments have been posted.</p>
{% get_comment_list for blog.blogpost 1 as comment_list %}
{% for comment in comment_list %}
<p>Posted by: {{ comment.user_name }} on {{ comment.submit_date }}</p>
<p>Comment: {{ comment.comment }}</p>
{% endfor %}
{% get_comment_form for blog.blogpost last_element.id as form %}
<!-- A context variable called form is created with the necessary hidden
fields, timestamps and security hashes -->
<table>
<form action="{% comment_form_target %}" method="post">
{% csrf_token %}
{{ form }}
<tr>
<td colspan="1">
<input type="submit" name="submit" value="Post">
<input type="submit" name="preview" value="Preview">
<input type="hidden" name="next" value="{% url 'comment_posted' %}" />
</td>
</tr>
</form>
</table>
{% get_comment_list for blog.blogpost last_element.id as comment_list %}
{%for comment in comment_list%}
<li><b>{{comment.name}}</b> has posted comment on {{comment.submit_date}} </li>
<ul><li>{{comment.comment}}</li></ul>
<a name="c{{ comment.id }}"></a>
<a href="{% get_comment_permalink comment %}">
see comment details
</a>
{%endfor%}
</p>
</div>
<div class="col-md-4">
<!-- Blog Search Well -->
<form action = "{%url 'blog_search'%}" method = "POST">
<div class="well">
<h4>Blog Search</h4>
<div class="input-group">
{%csrf_token%}
<input type="text" class="form-control" name = "keyword", placeholder = "Enter search keyword">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
<!-- /.input-group -->
</div>
</form>
<!-- Blog Categories Well -->
<div class="well">
<h4>Tags</h4>
<div class="row">
<div class="col-lg-6">
<ul class="list-unstyled">
<!-- {%for a in tags_list%}
<a href="">{{a}}</a>
{%endfor%} -->
<!-- {%for a in tags_list%}
<a href="">{{a}}</a>
{%endfor%} -->
{%for a in tags_list%}
<form id = 'form1' action = "{%url 'tag_search'%}" method = "POST">
{%csrf_token%}
<!-- <a href = "" name = 'tag'>{{a}},</a> -->
<!-- <a href="javascript:;" onclick="document.getElementById('form1').submit();" name = 'tag'>{{a}},</a> -->
<input type = 'submit' id = 'mybuttonlink' value = {{a}} name = 'tag'>
</form>
{%endfor%}
<!-- {%for a in tags_list%}
<a href="{%url 'tag_search'%}">{{a}}</a>
{%endfor%} -->
<!-- <li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li> -->
</ul>
</div>
<div class="col-lg-6">
<ul class="list-unstyled">
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
<li><a href="#">Category Name</a>
</li>
</ul>
</div>
</div>
<!-- /.row -->
</div>
<!-- Side Widget Well -->
<div class="well">
<h4>Side Widget Well</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, perspiciatis adipisci accusamus laudantium odit aliquam repellat tempore quos aspernatur vero.</p>
</div>
</div>
</div>
</div>
</div>
<!-- Blog Sidebar Widgets Column -->
<!-- /.row -->
<hr>
<!-- Footer -->
<footer>
<div class="row">
<div class="col-lg-12">
<p>Copyright © Your Website 2014</p>
</div>
</div>
<!-- /.row -->
</footer>
</div>
<!-- /.container -->
<!-- jQuery -->
{%block javascript%}
<script src="{%static 'js/jquery.js'%}"></script>
<!-- Bootstrap Core JavaScript -->
<script src="{%static 'js/bootstrap.min.js'%}"></script>
{%endblock javascript%}
</body>
</html>
from django.conf.urls import url, patterns
from django.contrib.auth.views import *
from . import views
from blog.templates.blog import *
urlpatterns = [
url(r'^home$', views.home, name = 'blog_home'),
url(r'^newpost$', views.new_post, name = 'blog_new_post'),
url(r'^login$', views.login_user, name = 'blog_login'),
url(r'^logout$', views.logout_user, name = 'blog_logout'),
url(r'^register$', views.register_user, name = 'blog_register'),
url(r'^resetpassword/passwordsent/$', password_reset_done, name = 'password_reset_done'),
url(r'^resetpassword/$', password_reset, name = 'password_reset'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$', password_reset_confirm, name = 'password_reset_confirm'),
url(r'^reset/done/$', password_reset_complete, name = 'password_reset_complete'),
url(r'^comments/posted', views.comment_posted, name = 'comment_posted'),
url(r'^blogsearch/', views.blog_search, name = 'blog_search'),
#url(r'^tagsearch/(?P<a>)', views.tag_search, name = 'tag_search'),
url(r'^tagsearch/', views.tag_search, name = 'tag_search'),
]
def logout_user(request):
logout(request)
return redirect(reverse('blog_home'))
def logout_user(request):
logout(request)
return reverse(redirect('home', request))
#return render(request, home)
url(r'^home$', views.home, name = 'blog_home'),
url(r'^home$', views.home, name='home')