1.
运行django-admin.py startproject mysite生成mysite站点,要把C:\Python27\Scripts(django-admin.py在此目录下)加入系统路径。
2.
D:\mysite>python manage.py runserver报错:
The problem is in functools.py file。
编辑C:\Python27\Lib\functools.py(大约第56行):
convert = { '__lt__': [('__gt__', lambda self, other: other < self),
换成:
convert = { '__lt__': [('__gt__', lambda self, other: not (self < other or self == other)),
(参考http://stackoverflow.com/questions/16259729/django-python-manage-py-runserver-gives-runtimeerror-maximum-recursion-depth-e)
再次运行python manage.py runserver正常!
―――分―――――――割――――――――线――――――――――――――――
其他报错
编号接上
3.python manage.py validate失败
django book中文档比较老旧,在settings.py中的install app列表中,不许要写‘project_name.app_name’,直接写‘app_name’即可。
比如:python manage.py startapp books
则settings.py中的配置如下:
INSTALLED_APPS = (
'books', # not 'project.books'
)
4.No module named books.models
>>>from mysite.books.models import Publisher,Author,Book,会出现以下的错误:
ImportError: No module named books.models
改成 from books.models import Book问题就解决了
5."Could not import django.views.generic.simple.direct_to_template. Parent module django.views.generic.simple does not exist."
direct_to_template() 在 django 取消了。
可以这么写
from django.conf.urls import patterns from django.views.generic import TemplateView urlpatterns = patterns('', (r'^$', TemplateView.as_view(template_name="index.html")), )
6.python错误:No module named six
安装scipy,将
site-packages\scipy\lib 目录下的三个文件
six.py
six.pyo
six.pyc
复制到site-packages目录下就可以了。
7.Site matching query does not exist
settings.py增加'django.contrib.sites'的时候,出现以下的错误:
Site matching query does not exist
http://stackoverflow.com/questions/9736975/django-admin-doesnotexist-at-admin这里找到答案,
You don't really need the sites
framework if you only run one site from the project, so the easiest fix would be to remove the following item from your INSTALLED_APPS
and the error should go away:
'django.contrib.sites'
You can also re-create the missing Site object from shell. Run python manage.py shell and then:
from django.contrib.sites.models import SiteSite.objects.create(pk=1, domain='www.example.com', name='example.com')
方法一是INSTALLED_APPS中注销掉'django.contrib.sites'
方法二是创建site对象:
python manage.py shel from django.contrib.sites.models import Site Site.objects.create(pk=2,domain='www.example.com',name='example.com')
8.
The string that could not be encoded/decoded was: "><b>
simpleTodo.html中有“<b>待办事项:</b>”的内容,是中文解码的问题。
经过查找,错误消息来自django/views/debug.py:
{% if unicode_hint %} <div id="unicode-hint"> <h2>Unicode error hint</h2> <p>The string that could not be encoded/decoded was: <strong>{{ unicode_hint|force_escape }}</strong></p> </div> {% endif %}
把“待办事项”改成“a”,错误仍在:
The string that could not be encoded/decoded was: ><b>a</b>
把“待办事项”清空,<b></b>之间再插入英文单词就正常了!