使用参数'()'和关键字参数'{}'找不到'index'。尝试过0种模式:[]

时间:2016-12-10 08:40:45

标签: python mysql django

这是view.py的索引函数

def index(request):
	logger_user_id = None
	if 'id' in request.session:
		request.user.is_active = True
		logger_user_id = request.session['id']
		print(logger_user_id)


	posts = Post.objects.all()

	all_users = User.objects.all();

	author_name = {}

	for e in posts:
		author_name[e.id] = get_object_or_404(User, id=e.user_id).username
		e.likes_count = Likes.objects.filter(post_id=e.id).count()


		try:
			post_logger_like = Likes.objects.get(user_id=logger_user_id, post_id=e.id)
			e.logger_like = 1
		except Likes.DoesNotExist:
		
			e.logger_like = None

		

		recent_liker = Likes.objects.filter(post_id=e.id).exclude(user_id=logger_user_id).order_by('-liked_date')[:2]
		
		e.liker_count = recent_liker.count();

		



		if (e.liker_count == 2):
			e.postliker1 = get_object_or_404(User, id=recent_liker[e.liker_count - 2].user_id).username
			e.postliker2 = get_object_or_404(User, id=recent_liker[e.liker_count - 1].user_id).username

		if (e.liker_count == 1):
			e.postliker1 = get_object_or_404(User, id=recent_liker[e.liker_count - 1].user_id).username

	for e in posts:
		print(e.liker_count)
	
	all_comments = Comment.objects.all()

	commentor_names = {}

	for e in all_comments:
	
		commentor_names[e.id] = get_object_or_404(User, id=e.user_id).username

	all_replies = Reply.objects.all()

	replier_names = {}

	for e in all_replies:
	
		replier_names[e.id] = get_object_or_404(User, id=e.user_id).username
		

	if (logger_user_id is not None):
		#return HttpResponse("<h1> hello user "+str(logger_user_id)+"</h1>")
		return render(request, 'mysite/_index.html',
					  {'posts': posts, 'replies': all_replies, 'comments': all_comments, 'author_name': author_name,
					   'commentor_names': commentor_names, 'replier_names': replier_names,
					   'logger_user_id': logger_user_id})

	else:
		return render(request, 'mysite/_index.html',
					  {'posts': posts, 'replies': all_replies, 'comments': all_comments, 'author_name': author_name,
					   'commentor_names': commentor_names, 'replier_names': replier_names, })

我是python中的新手我在最近的django项目中遇到错误,即“反向'索引',参数'()'和关键字参数'{}'找不到。0模式尝试:[] “这个错误是什么意思..请解释错误。这个错误对我来说并不清楚。

我使用django 1.10.3和MySql作为我的后端[浏览器出错

高级谢谢。

{% load staticfiles %}

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->

   <link rel="icon favicon" href="img/logo.png">
      <link rel="stylesheet" type="text/css" href="{% static 'mysite/css/demo.css' %}" />
      <link rel="stylesheet" type="text/css" href="{% static 'mysite/css/style2.css' %}" />      
      <link href="{% static 'mysite/css/font.css' %}" rel='stylesheet' type='text/css'>
      <noscript>
        <link rel="stylesheet" type="text/css" href="{% static 'mysite/css/nojs.css' %}" />
      </noscript> 
      <script src="{% static 'mysite/js/jquery.min.js' %}"></script>
      <!-- Bootstrap -->
      <!--<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">-->
      <link href="{% static 'mysite/css/style.css' %}" rel="stylesheet">
      <link href="{% static 'mysite/css/normalize.css' %}" rel="stylesheet">        
      <link href="{% static 'mysite/css/google_font.css' %}" rel="stylesheet">
      <link href="{% static 'mysite/css/font-awesome.min.css' %}" rel="stylesheet">        
      <link href="{% static 'mysite/css/animate.min.css' %}" rel="stylesheet">            
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>       
      <script src="{% static 'mysite/js/jquery.nicescroll.min.js' %}"></script>
      <script src="{% static 'mysite/js/jquery.easing.1.3.js' %}"></script> 


</head>


<body>

<div class="header">
    <img src="{% static 'mysite/img/top.png' %}" class="img-responsive">
</div>


<div class="wrapper">
    <div class="row-offcanvas row-offcanvas-left">

        <!-- main right col -->
        <!--<div class="column col-sm-12 col-xs-12" id="main">-->

        <!-- top nav -->

        <div id="custom-bootstrap-menu" class="navbar navbar-default " role="navigation">
            <div class="container-fluid">
                <div class="navbar-header"><a class="navbar-brand" href="#"> </a>
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                            data-target=".navbar-menubuilder"><span class="sr-only">Toggle navigation</span><span
                            class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>
                    </button>
                </div>


                <div class="collapse navbar-collapse navbar-menubuilder">
                    <ul class="nav navbar-nav navbar-left">
                        <li><a href="{% url 'mysite:index' %}"><i class="glyphicon glyphicon-home"></i> Home</a>
                        </li>
                        <li><a href="#" id="myBtn"><i class="glyphicon glyphicon-plus"></i> Post</a>
                            <!-- modal 1 button -->
                        </li>

                    </ul>
                    {% if request.user.is_active %}
                    <ul class="nav navbar-nav navbar-right">

                        <li>
                            <a href="#"><i class="glyphicon glyphicon-home"></i> Home</a>
                        </li>
                        <li>
                            <a href="#" role="button" data-toggle="modal"><i
                                    class="glyphicon glyphicon-plus"></i> New Post</a>
                        </li>
                        <li>

                            <a href="#" role="button" data-toggle="modal"><i
                                    class="glyphicon glyphicon-th"></i> my Posts</a>
                        </li>
                        <li>

                            <a href="#" role="button" data-toggle="modal"><i
                                    class="glyphicon glyphicon-log-out"></i> log-out</a>
                        </li>
                    </ul>

                    {% else %}

                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="{% url 'mysite:login' %}">Log In</a>
                        </li>
                        <li><a href="{% url 'mysite:register' %}">Register</a>
                        </li>
                        <form class="navbar-form navbar-right">
                            <div class="input-group input-group-sm" style="max-width:350px;">
                                <input type="text" class="form-control" placeholder="Search" name="srch-term"
                                       id="srch-term">
                                <div class="input-group-btn">
                                    <button class="btn btn-default" type="submit"><i
                                            class="glyphicon glyphicon-search"></i></button>
                                </div>
                            </div>
                        </form>

                    </ul>
                    {% endif %}
                </div>
            </div>
        </div>
        <!-- /top nav -->
        <!-- __________________________________________________ -->


        <!-- Modal -->
        <div class="modal fade" id="myModal" role="dialog">
            <div class="modal-dialog">

                <!-- Modal content-->
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title text-center">Add Your Post Here</h4>
                    </div>
                    <div class="modal-body">

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>


        <!-- sidebar -->
        <div class="column col-sm-2 col-xs-1 sidebar-offcanvas" id="sidebar">

            <ul class="nav">
                <li><a href="#" data-toggle="offcanvas" class="visible-xs text-center"><i
                        class="glyphicon glyphicon-chevron-right"></i></a></li>
            </ul>

            <ul class="nav hidden-xs" id="lg-menu">


                <li class="active"><a href="{% url 'mysite:favourite' %}"><i class="fa fa-star" aria-hidden="true"></i>
                    Favourite</a></li>






                <li><a href="{% url 'mysite:instructions_for_use' %}"><i class="glyphicon glyphicon-list"></i> Instructions for use</a></li>
        <li><a href="{% url 'mysite:copyrights' %}"><i class="glyphicon glyphicon-list"></i> Copyrights</a></li>
        <li><a href="{% url 'mysite:privacy_policy' %}"><i class="glyphicon glyphicon-list"></i> Privacy Policy</a></li>
        <li><a href="{% url 'mysite:about_us' %}"><i class="glyphicon glyphicon-list"></i> About Us</a></li>




                <li><a href="#"><i class="glyphicon glyphicon-paperclip"></i> Saved</a></li>
                <li><a href="#"><i class="glyphicon glyphicon-refresh"></i> Refresh</a></li>
            </ul>

            <!-- tiny only nav-->
            <ul class="nav visible-xs" id="xs-menu">
                <li><a href="#featured" class="text-center"><i class="glyphicon glyphicon-list-alt"></i></a></li>
                <li><a href="#stories" class="text-center"><i class="glyphicon glyphicon-list"></i></a></li>
                <li><a href="#" class="text-center"><i class="glyphicon glyphicon-paperclip"></i></a></li>
                <li><a href="#" class="text-center"><i class="glyphicon glyphicon-refresh"></i></a></li>
            </ul>

        </div>
        <!-- /sidebar -->

        <!-- ------------------------------body of content--------------------------------- -->

        <!-- /sidebar -->

        <div class="full col-sm-10 col-xs-10">
            {% block content %}

            {% endblock %}

            <!-- -------------------------footer---------------------- -->
            <div class="panel panel-default">

                <div class="panel-body">
                    <div class="partner text-center">
                        <img src="{% static 'img/company-logo.jpg' %}">


                    </div>

                    <hr>
                    <div class="footer">


                        <p class="text-center">Copyright (cc) 2006-2013 RIKEN BSI Neuroinformatics Japan Center, Some
                            rights
                            reserved.</p>
                    </div>


                </div>
            </div>

        </div>


        <!--</div>-->
    </div>
</div>

</body>
</html>

] 1

urlpatterns = [
    #/mysite/
    url(r'^$', views.index, name='index'),
	url(r'register/$', views.registration, name='register'),
	url(r'login/$', views.login, name='login'),
	url(r'^favourite/$', views.favourite, name='favourite'),
	url(r'^instructions_for_use/$', views.instructions_for_use, name='instructions_for_use'),
    url(r'^copyrights/$', views.copyrights, name='copyrights'),
    url(r'^privacy_policy/$', views.privacy_policy, name='privacy_policy'),
    url(r'^about_us/$', views.about_us, name='about_us'),
	url(r'pubmed_entry/$', views.pubmed_entry, name='pubmed_entry'),
	url(r'^like/$', views.like, name="likes"),
]

0 个答案:

没有答案