reverse()的/Error参数必须是一个序列而不改变任何东西

时间:2016-08-13 19:29:40

标签: python django

我的django应用程序存在一个大问题:在我停止处理我的应用程序一个月后,我得到了错误"在reverse()的/ argument处的TypeError必须是一个序列" 当我加载页面。

完全错误:

`In template Internal Server Error: /
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)


File "/Users/nicholaslamprecht/GitHub/nictec_website2.0/nictecsite/page/views.py", line 11, in index
    return render(request, 'page/index.html', {'news':news1})
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/shortcuts.py", line 67, in render
    template_name, context, request=request, using=using)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/loader.py", line 97, in render_to_string
    return template.render(context, request)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py", line 197, in _render
    return self.nodelist.render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)



 File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/template/defaulttags.py", line 499, in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 600, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))



File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 448, in _reverse_with_prefix
    self._populate()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 316, in _populate
    for name in pattern.reverse_dict:
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-

packages/django/core/urlresolvers.py", line 346, in reverse_dict
    self._populate()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 293, in _populate
    for pattern in reversed(self.url_patterns):
TypeError: argument to reversed() must be a sequence
[14/Aug/2016 06:55:14] "GET / HTTP/1.1" 500 129729

root urls.py:

"""nictecsite URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
Class-based views


 1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include

from django.contrib import admin

urlpatterns = [
    url(r'^database/', admin.site.urls),  
    url(r'^', include('page.urls')),
    url(r'^lager/', include('storage.urls')), 
    url(r'^admin/', include('backend.urls')),
]

应用程序的urls.py(对不起德语名称):

from django.conf.urls import url, include
from django.contrib import admin 
from page import views  
from django.contrib.auth.views import login, logout



urlpatterns = [
   url(r'^$', views.index, name= 'index'),
   url(r'^lichtpakete/', views.light, name= 'licht'), 
   url(r'^beschallungspakete/', views.audio, name= 'ton'), 
   url(r'^Kontakt/', views.contact, name= 'kontakt'), 
   url(r'^technik/', views.tec, name= 'technik'),
   url(r'^ueber uns/', views.ueber,  name= 'ueber'), 
   url(r'^intern/login/$',login, name='login'),
   url(r'^loggedin/', views.loggedin, name= 'loggedin'), 
   url(r'^intern/loggedout', views.loggedout),
   url(r'intern/logout', views.logout_view, name='logout'),
]

views.py:

from django.shortcuts import render 
from django.contrib.auth.decorators import login_required
from django.utils import timezone
from .models import news


# Create your views here. 
def index(request):  
    news1 = news.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
    if news1:
        return render(request, 'page/index.html', {'news':news1}) 
    else:
        print('error')
        return render(request, 'page/licht.html')

def light(request): 
    return render(request, 'page/licht.html') 

def audio(request): 
    return render(request, 'page/beschallung.html') 

def contact(request): 
    return render(request, 'page/buchung.html') 

def tec(request): 
    return render(request, 'page/technik.html') 

def ueber(request): 
    return render(request, 'page/ueber.html')  

def logout_view(request): 
    auth.logout(request) 
    return HttpResponseRedirect("intern/loggedout/")

@login_required
def loggedin(request): 
    return render(request, 'page/loggedin.html')  

def loggedout(request): 
    return render(request, 'page/loggedout.html')

index.html:



<!DOCTYPE html>
<html lang="en">
<head> 
    {% load staticfiles %}
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">  
    <!--Bootstrap CSS delivered by a content delivery system-->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">  
      <!--custom css-->
   <link rel="stylesheet" href="{% static "page/css/custom.css" %}"> 
    <!--favicon-->
    <link rel="shortcut icon" type="image/png" href="{% static "page/pictures/favicon.ico" %}"/>
    
    <!--javascript for transparent header--> 
     <script src="{% static "page/javascript/transparent.js" %}"></script>
    
    <title>Nictec Home</title>
</head>   
<body> 
    <!--navigation--> 
    <nav role="navigation" id="navbar" class="navbar navbar-inverse navbar-fixed-top">  
    
        <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                </button>
                <a href="{% url 'index' %}"><img class="navbar-brand" src= "{% static "page/pictures/logo_heller.png"  %}"/></a>
            </div> 
            
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav"> 
                    <!--Links-->
                    <li><a href="{% url 'index' %}">HOME </a></li> 
                    
                     <li class="dropdown">
                        <a href="{% url 'licht' %}" class="dropdown-toggle" role="button" aria-haspopup="true" aria-expanded="false">LICHTPAKETE <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Licht mini</a></li>
                            <li><a href="#">Licht small</a></li>
                      
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a href="{% url 'ton' %}" class="dropdown-toggle"  role="button" aria-haspopup="true" aria-expanded="false">BESCHALLUNGSPAKETE <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Beschallung mini</a></li>
                          
                        </ul>
                    </li>  
                    <li><a href="{% url 'kontakt' %}">KONTAKT/BUCHUNG</a></li> 
                    <li><a href="{% url 'technik' %}">TECHNIK</a></li> 
                
                    <li class="dropdown">
                        <a href="{% url 'ueber' %}" class="dropdown-toggle"  role="button" aria-haspopup="true" aria-expanded="false">ÜBER UNS <span class="caret"></span></a>
                        <ul class="dropdown-menu"> 
                             <li><a href="#">Impressum</a></li> 
                             <li><a href="#">Datenschutz</a></li>
                          
                        </ul>
                    </li>  
                </ul>
          
         
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="{% url 'login' %}">Login für Miarbeiter</a></li>
            
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav> 


            
        
    <!--carousel-->    
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner" role="listbox">
        <div class="item active">
            <img src="{% static "page/pictures/banner-landing.jpg" %}" alt="banner"/ id= "picture">
        </div>
    
        <!-- Left and right controls -->
        <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
            <span class="sr-only">Next</span>
          </a> 
          
        </div> 
         
        <!--page header--> 
        <div class="page-header">
            <h1>News</h1>  
        </div>
        <!--content--> 
        
        <div class="wrapper">  
           <div id= database>
            {% for news in news %}
                <h3><a href="">{{ news.title }}</a></h3>
                <p>{{ news.text|linebreaksbr }}</p> 
            {% endfor %} 
           </div>
        </div> 
      
        
        <!--footer--> 
        <div class="footer navbar-inverse navbar-default-bottom" role="navigation">
        <div class="navbar-text pull-left"></div>
        <div class="container"> 
            <div class="navbar-text pull-left">
                  <p>© Nictec Veranstaltungstechnik. Alle Rechte vorbehalten. </p>
        
        </div> 
    </div> 
</div>  
    
    
            
        </div> 
      
        
        
        
        
       <!--ajax and jquery loading script--> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    </body>
    
</html>
&#13;
&#13;
&#13;

编辑:如果我删除根urls.py中的url(r'^admin/', include('backend.urls')),问题已解决,但我需要此条目。

如果您需要更多信息,请写评论。 提前致谢

0 个答案:

没有答案