zoukankan      html  css  js  c++  java
  • django


    查看django版本:

    F:>python -c "import django;print django.VERSION;print django.get_version();"
    (1, 8, 0, 'final', 0)
    1.8
    
    F:>
    F:>python
    Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on wi
    n32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import django
    >>> django.VERSION
    (1, 8, 0, 'final', 0)
    >>> django.get_version()
    '1.8'
    >>>
    u'polls' is not a registered namespace
    Request Method:    GET
    Request URL:    http://127.0.0.1:8000/polls/2/
    Django Version:    1.8
    Exception Type:    NoReverseMatch
    Exception Value:    
    u'polls' is not a registered namespace
    Exception Location:    C:Python27libsite-packagesdjangocoreurlresolvers.py in reverse, line 575
    Python Executable:    C:Python27python.exe
    Python Version:    2.7.10
    In template F:python	csitepolls	emplatespollsdetail.html, error at line 13
    u'polls' is not a registered namespace
    3    <html>
    4    <head>
    5        <title>detail:{{ question }}</title>
    6    </head>
    7    <body>
    8    
    9    <h1>{{ question.question_text }}</h1>
    10    
    11    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    12    
    13    
          <form action="
          {% url 'polls:vote' question.id %}
          " method="post">
    
          
    14        {% csrf_token %}
    15        {% for choice in question.choice_set.all %}
    16            <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"/>
    17            <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br/>
    18        {% endfor %}
    19        <input type="submit" value="Vote"/>
    20    </form>
    21    
    22    <hr/>
    23    <!--

    解决办法:
    将F:python csiteurls.py中

    url(r'^polls/', include('polls.urls')),
    改为
    url(r'^polls/', include('polls.urls', namespace="polls")),

    在项目/url.py中的include参数增加namespace="polls"后,上述问题解决,但在打开http://127.0.0.1:8000/polls/时报错:

    Reverse for 'detail' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
    Request Method:    GET
    Request URL:    http://127.0.0.1:8000/polls/
    Django Version:    1.8.5
    Exception Type:    NoReverseMatch
    Exception Value:    
    Reverse for 'detail' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
    Exception Location:    D:Python27libsite-packagesdjangocoreurlresolvers.py in _reverse_with_prefix, line 495
    Python Executable:    D:Python27python.exe
    Python Version:    2.7.8
    Error during template rendering
    
    In template F:python	csitepolls	emplatespollsindex.html, error at line 11
    Reverse for 'detail' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
    1    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    2            "http://www.w3.org/TR/html4/loose.dtd">
    3    <html>
    4    <head>
    5        <title>polls</title>
    6    </head>
    7    <body>
    8    {% if latest_question_list %}
    9        <ul>
    10            {% for question in latest_question_list %}
    11    
                      <li><a href="
          {% url 'detail' question.id %}
          ">{{ question.question_text }}</a></li>
    
          
    12            {% endfor %}
    13        </ul>
    14    {% else %}
    15        <p>No polls are available.</p>
    16    {% endif %}
    17    </body>
    18    </html>

    解决办法:
    将第index.html第11行

    <li><a href="{% url 'detail' question.id %}">{{ question.question_text }}</a></li>
    改为:
    <li><a href="{% url 'polls:detail' question.id %}">{{ question.question_text }}</a></li>

    http://stackoverflow.com/questions/33151816/noreversematch-at-polls-django-tutorial

  • 相关阅读:
    旺财速啃H5框架之Bootstrap(二)
    Java 8 的 Nashorn 脚本引擎教程
    kindeditor4整合SyntaxHighlighter,让代码亮起来
    让kindeditor显示高亮代码
    css伪元素用法大全
    弹性布局基础讲解与高效应用
    美化页面,从我做起
    深度理解微信小程序的思想
    程序员提升之道-人际交往篇
    前端-网站构建从零开始
  • 原文地址:https://www.cnblogs.com/softidea/p/4925136.html
Copyright © 2011-2022 走看看