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:\Python27\lib\site-packages\django\core\urlresolvers.py in reverse, line 575
Python Executable:    C:\Python27\python.exe
Python Version:    2.7.10
In template F:\python\tcsite\polls\templates\polls\detail.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\tcsite\urls.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:\Python27\lib\site-packages\django\core\urlresolvers.py in _reverse_with_prefix, line 495
Python Executable:    D:\Python27\python.exe
Python Version:    2.7.8
Error during template rendering

In template F:\python\tcsite\polls\templates\polls\index.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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值