django

简介: 查看django版本: F:\>python -c "import django;print django.VERSION;print django.get_version();" (1, 8, 0, 'final', 0) 1.


查看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

 

相关文章
|
7月前
|
Python
Django由一查多
Django由一查多
|
4月前
|
缓存 安全 API
Django
Django是一个用Python编写的开源Web框架,用于构建可扩展、高性能、安全的Web应用程序。Django具有许多内置功能,如用户认证、管理界面、缓存、静态文件处理等,可以帮助开发者快速搭建和开发Web应用程序。 Django的用途主要包括:
62 1
|
8月前
|
Python
初识Django
初识Django
45 0
|
设计模式 缓存 前端开发
Django——小结
 Python的WEB框架有Django、Tornado、Flask 等多种,Django是重量级选手中最有代表性的一位,它的优势为:大而全,框架本身集成了ORM、模型绑定、模板引擎、缓存、Session等诸多功能。
108 0
Django——小结
|
数据库 数据安全/隐私保护 Python
|
Python
Django 项目重命名
  在日常学习工作过程中,我们难免需要复用以前的项目,这里讲下复用 Django 项目并重命名的过程。 1.修改项目名称,使用 pycharm -> refactor 重命名整个项目。   2.修改 manage.py 和 Django 下和项目名称相同的文件夹,使用 grep 指令找出和项目有关的字符串,如: grep 'test4' *.py 逐一修改。
4494 0
|
前端开发
Django-SerializerMethodField
DRF-Serializer-SerializerMethodField,更加灵活的修改返回给前端的数据
|
算法 前端开发 程序员
初识Django(一)
什么Django        Django是一个开放源代码的Web应用框架,由Python写成。采用了MVC的框架模式,即模型M,视图V和控制器C。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CMS(内容管理系统)软件。
1553 0
|
Web App开发 前端开发 数据库
Django中的ModelForm
一、ModelForm的基本用法示例: from django import forms from app01 import models class BookModelForm(forms.
1152 0