通过Django教程,我已经运行了django-admin startproject mysite.现在我无法完成下一步的工作.
$ python manage.py runserver
>>>
$
Run Code Online (Sandbox Code Playgroud)
其中空白行是Ctrl-C输入的位置以打破循环.这>>>是我为virtualenv定义的提示.换句话说,没有输出.
最重要的是,我在连接时遇到连接拒绝错误http://127.0.0.1:8000.如教程中所述,我没有得到"'欢迎来到Django'页面,令人愉快的浅蓝色粉彩".
其他命令python manage.py正常工作.例如:
$ python manage.py check
System check identified no issues (0 silenced).
$ python manage.py shell --command 'import sys; print(sys.version)'
3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:27:37) [MSC v.1900 64 bit (AMD64)]
$/ python manage.py shell --command 'import django; print(django.__version__)'
1.11.2
Run Code Online (Sandbox Code Playgroud)
我对如何进一步探索感到茫然.我试过了:
我可以使用 Python 的 unittest assertLogs 来检查日志消息的格式吗?
def test_log_format(self):
h.config_common_log(level=logging.DEBUG)
h.get_log().debug('outside context')
with self.assertLogs(level=logging.DEBUG) as a_log:
h.get_log().debug('my_message - incontext')
self.assertRegex(a_log.output[0], ':\d+:my_message') # This fails
# This shows the log data itself is correct, just the output message is wrong
print('a_log.ouput={}\ta_log={!s}'.format(a_log.output, a_log))
# This was added to learn varying the logger would help. It did not.
def get_log():
return logging.getLogger()
def config_common_log(level=logging.WARNING):
get_log().setLevel(level)
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter('%(module)s:%(funcName)s:%(lineno)s:%(message)s')) # Despite this format statement.
get_log().addHandler(ch)
Run Code Online (Sandbox Code Playgroud)
让我感到困惑的是“外部上下文”日志消息包含行号,但“我的消息 - 在上下文中”日志消息显示默认格式。
我目前的假设是 assertLogs 只检查一个 StreamHandler 并且(相当合理)它使用默认的 StreamHandler …