Unhandled exception in thread started by
Traceback (most recent call last):
File "/home/toohoo/.local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
self.check(display_num_errors=True)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
include_deployment_checks=include_deployment_checks,
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
return checks.run_checks(**kwargs)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
return check_resolver(resolver)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
return check_method()
File "/home/toohoo/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 256, in check
for pattern in self.url_patterns:
File "/home/toohoo/.local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/toohoo/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 416, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '__main__' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
Performing system checks...
解决方法:URL映射出错,在后面加上逗号(,),服务器跑起来了。基础待加强。。。
urlpatterns = (
url(r'^$',index),
)
源文件first.py如下:
import os
import sys
from django.conf import settings
DEBUG = os.environ.get('DEBUG','on') == 'on'
SECRET_KEY = os.environ.get('SECRET_KEY',os.urandom(32))
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS','localhost').split(',')
settings.configure(
DEBUG = DEBUG,
SECRET_KEY = SECRET_KEY,
ALLOWED_HOSTS = ALLOWED_HOSTS,
ROOT_URLCONF = __name__
)
from django.conf.urls import url
from django.http import HttpResponse
def index(request):
return HttpResponse('Hello World')
urlpatterns = (
url(r'^$',index),
)
if __name__ == '__main__':
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)