c:\Dev>django-admin startproject mysite
将以下内容(从https://docs.djangoproject.com/en/1.8/topics/logging/复制)添加到c:\ Dev \ mysite \ mysite \ settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'c:/Dev/mysite/debug.log',
},
},
'loggers': {
'django.request': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
迁移,运行开发服务器,然后在浏览器中访问http://127.0.0.1:8000/:
c:\Dev>cd mysite
c:\Dev\mysite>python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: admin, contenttypes, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
c:\Dev\mysite>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
September 21, 2015 - 15:52:25
Django version 1.8.4, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[21/Sep/2015 15:52:27] "GET / HTTP/1.1" 200 1767
为什么每个页面加载Not Found: /
?
c:\Dev\mysite\debug.log
的日志文件也包含Not Found: /
。答案 0 :(得分:0)
groupType
中的代码正在记录"Not Found: /"
(在django.core.handlers.base.py
方法中)。您不会看到您是否未配置日志记录,但如果您执行配置日志记录并且不具有“/”URL的处理程序,则会看到它你的urlconfs。
您在日志输出中看到的200是因为Django使用默认响应处理了404个案例。