1 [root@localhost FLchatterbot]# python3 manage.py startapp bot 2 Traceback (most recent call last): 3 File "manage.py", line 22, in <module> 4 execute_from_command_line(sys.argv) 5 File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line 6 utility.execute() 7 File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 347, in execute 8 django.setup() 9 File "/usr/local/lib/python3.5/site-packages/django/__init__.py", line 24, in setup 10 apps.populate(settings.INSTALLED_APPS) 11 File "/usr/local/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate 12 app_config.import_models() 13 File "/usr/local/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models 14 self.models_module = import_module(models_module_name) 15 File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module 16 return _bootstrap._gcd_import(name[level:], package, level) 17 File "<frozen importlib._bootstrap>", line 986, in _gcd_import 18 File "<frozen importlib._bootstrap>", line 969, in _find_and_load 19 File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 20 File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 21 File "<frozen importlib._bootstrap_external>", line 662, in exec_module 22 File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 23 File "/usr/local/lib/python3.5/site-packages/chatterbot/ext/django_chatterbot/models.py", line 129, in <module> 24 class AbstractBaseResponse(models.Model): 25 File "/usr/local/lib/python3.5/site-packages/chatterbot/ext/django_chatterbot/models.py", line 138, in AbstractBaseResponse 26 related_name='in_response' 27 TypeError: __init__() missing 1 required positional argument: 'on_delete'
下面时我的内容
1 """ 2 Django settings for FLchatterbot project. 3 4 Generated by 'django-admin startproject' using Django 1.11.7. 5 6 For more information on this file, see 7 https://docs.djangoproject.com/en/1.11/topics/settings/ 8 9 For the full list of settings and their values, see 10 https://docs.djangoproject.com/en/1.11/ref/settings/ 11 """ 12 13 import os 14 15 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 18 19 # Quick-start development settings - unsuitable for production 20 # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 22 # SECURITY WARNING: keep the secret key used in production secret! 23 SECRET_KEY = 'r$f@_ut^gf0*t!rjw+4_yh=33($p7#zp4%@oaaio9s$o3lv)1u' 24 25 # SECURITY WARNING: don't run with debug turned on in production! 26 DEBUG = True 27 28 ALLOWED_HOSTS = ['*'] 29 30 31 # Application definition 32 33 INSTALLED_APPS = [ 34 'django.contrib.admin', 35 'django.contrib.auth', 36 'django.contrib.contenttypes', 37 'django.contrib.sessions', 38 'django.contrib.messages', 39 'django.contrib.staticfiles', 40 'chatterbot.ext.django_chatterbot', 41 'bot', 42 'gunicorn', 43 ] 44 45 CHATTERBOT = { 46 'name':'FLbot', 47 'storage_adapter':'mongodbn.MongoDatabaseAdapter', 48 'logic_adapters':[ 49 #{ 50 # "import_path": "chatterbot.logic.BestMatch", 51 # "statement_comparison_function": "chatterbot.comparisons.levenshtein_distance", 52 # "response_selection_method": "chatterbot.response_selection.get_first_response" 53 #}, 54 { 55 'import_path': 'testlogic.MyLogicAdapter' 56 }, 57 #{ 58 # 'import_path': 'chatterbot.logic.LowConfidenceAdapter', 59 # 'threshold': 0.65, 60 # 'default_response': '我还不知道=?=' 61 #}, 62 'chatterbot.logic.MathematicalEvaluation', 63 ], 64 'database':'chatterbot-10w', 65 'database_uri':"mongodb://192.168.5.22:27017/", 66 'read_only':'True', 67 'django_app_name':'FLchatterbot', 68 } 69 70 MIDDLEWARE = [ 71 'django.middleware.security.SecurityMiddleware', 72 'django.contrib.sessions.middleware.SessionMiddleware', 73 'django.middleware.common.CommonMiddleware', 74 #'django.middleware.csrf.CsrfViewMiddleware', 75 'django.contrib.auth.middleware.AuthenticationMiddleware', 76 'django.contrib.messages.middleware.MessageMiddleware', 77 'django.middleware.clickjacking.XFrameOptionsMiddleware', 78 ] 79 80 ROOT_URLCONF = 'FLchatterbot.urls' 81 82 83 TEMPLATES = [ 84 { 85 'BACKEND': 'django.template.backends.django.DjangoTemplates', 86 'DIRS': [], 87 'APP_DIRS': True, 88 'OPTIONS': { 89 'context_processors': [ 90 'django.template.context_processors.debug', 91 'django.template.context_processors.request', 92 'django.contrib.auth.context_processors.auth', 93 'django.contrib.messages.context_processors.messages', 94 ], 95 }, 96 }, 97 ] 98 99 WSGI_APPLICATION = 'FLchatterbot.wsgi.application' 100 101 102 # Database 103 # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 104 105 DATABASES = { 106 'default': { 107 'ENGINE': 'django.db.backends.sqlite3', 108 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 109 } 110 } 111 112 113 # Password validation 114 # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 115 116 AUTH_PASSWORD_VALIDATORS = [ 117 { 118 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 119 }, 120 { 121 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 122 }, 123 { 124 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 125 }, 126 { 127 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 128 }, 129 ] 130 131 132 # Internationalization 133 # https://docs.djangoproject.com/en/1.11/topics/i18n/ 134 135 LANGUAGE_CODE = 'en-us' 136 137 TIME_ZONE = 'UTC' 138 139 USE_I18N = True 140 141 USE_L10N = True 142 143 USE_TZ = True 144 145 146 # Static files (CSS, JavaScript, Images) 147 # https://docs.djangoproject.com/en/1.11/howto/static-files/ 148 149 STATIC_URL = '/static/' 150 STATICFILES_DIRS = ( 151 os.path.join( 152 os.path.dirname(__file__), 153 'static', 154 ), 155 )
1 #!/usr/bin/env python 2 import os 3 import sys 4 5 if __name__ == "__main__": 6 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "FLchatterbot.settings") 7 try: 8 from django.core.management import execute_from_command_line 9 except ImportError: 10 # The above import may fail for some other reason. Ensure that the 11 # issue is really that Django is missing to avoid masking other 12 # exceptions on Python 2. 13 try: 14 import django 15 except ImportError: 16 raise ImportError( 17 "Couldn't import Django. Are you sure it's installed and " 18 "available on your PYTHONPATH environment variable? Did you " 19 "forget to activate a virtual environment?" 20 ) 21 raise 22 execute_from_command_line(sys.argv)
你的model.py文件有贴出来吗?
这是我改完之后报的错误
1 [root@localhost FLchatterbot]# python3 manage.py migrate 2 Traceback (most recent call last): 3 File "manage.py", line 22, in <module> 4 execute_from_command_line(sys.argv) 5 File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line 6 utility.execute() 7 File "/usr/local/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute 8 self.fetch_command(subcommand).run_from_argv(self.argv) 9 File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv 10 self.execute(*args, **cmd_options) 11 File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 332, in execute 12 self.check() 13 File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check 14 include_deployment_checks=include_deployment_checks, 15 File "/usr/local/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 58, in _run_checks 16 issues.extend(super()._run_checks(**kwargs)) 17 File "/usr/local/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks 18 return checks.run_checks(**kwargs) 19 File "/usr/local/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks 20 new_errors = check(app_configs=app_configs) 21 File "/usr/local/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config 22 return check_resolver(resolver) 23 File "/usr/local/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver 24 return check_method() 25 File "/usr/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 397, in check 26 for pattern in self.url_patterns: 27 File "/usr/local/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__ 28 res = instance.__dict__[self.name] = self.func(instance) 29 File "/usr/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 536, in url_patterns 30 patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) 31 File "/usr/local/lib/python3.5/site-packages/django/utils/functional.py", line 36, in __get__ 32 res = instance.__dict__[self.name] = self.func(instance) 33 File "/usr/local/lib/python3.5/site-packages/django/urls/resolvers.py", line 529, in urlconf_module 34 return import_module(self.urlconf_name) 35 File "/usr/local/lib/python3.5/importlib/__init__.py", line 126, in import_module 36 return _bootstrap._gcd_import(name[level:], package, level) 37 File "<frozen importlib._bootstrap>", line 986, in _gcd_import 38 File "<frozen importlib._bootstrap>", line 969, in _find_and_load 39 File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 40 File "<frozen importlib._bootstrap>", line 673, in _load_unlocked 41 File "<frozen importlib._bootstrap_external>", line 662, in exec_module 42 File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 43 File "/root/Desktop/chatterbot/FLchatterbot/FLchatterbot/urls.py", line 28, in <module> 44 url(r'^api/chatterbot/', include(chatterbot_urls, namespace='chatterbot')), 45 File "/usr/local/lib/python3.5/site-packages/django/urls/conf.py", line 39, in include 46 'Specifying a namespace in include() without providing an app_name ' 47 django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead
下面是我的urls.py
1 """FLchatterbot URL Configuration 2 3 The `urlpatterns` list routes URLs to views. For more information please see: 4 https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 Examples: 6 Function views 7 1. Add an import: from my_app import views 8 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 Class-based views 10 1. Add an import: from other_app.views import Home 11 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 Including another URLconf 13 1. Import the include() function: from django.urls import include, path 14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 """ 16 from django.contrib import admin 17 from django.urls import path 18 from django.conf.urls import url, include 19 from chatterbot.ext.django_chatterbot import urls as chatterbot_urls 20 from bot import views 21 22 23 urlpatterns = [ 24 path('admin/', admin.site.urls), 25 url(r'^$', views.ChatterBotAppView.as_view(), name='main'), 26 url(r'^admin/', admin.site.urls, name='admin'), 27 url(r'^api/chatterbot/', include(chatterbot_urls, namespace='chatterbot')), 28 29 30 ]
下面是我的settings.py
1 """ 2 Django settings for FLchatterbot project. 3 4 Generated by 'django-admin startproject' using Django 1.11.7. 5 6 For more information on this file, see 7 https://docs.djangoproject.com/en/1.11/topics/settings/ 8 9 For the full list of settings and their values, see 10 https://docs.djangoproject.com/en/1.11/ref/settings/ 11 """ 12 13 import os 14 15 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 18 19 # Quick-start development settings - unsuitable for production 20 # See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 21 22 # SECURITY WARNING: keep the secret key used in production secret! 23 SECRET_KEY = 'r$f@_ut^gf0*t!rjw+4_yh=33($p7#zp4%@oaaio9s$o3lv)1u' 24 25 # SECURITY WARNING: don't run with debug turned on in production! 26 DEBUG = True 27 28 ALLOWED_HOSTS = ['*'] 29 30 31 # Application definition 32 33 INSTALLED_APPS = [ 34 'django.contrib.admin', 35 'django.contrib.auth', 36 'django.contrib.contenttypes', 37 'django.contrib.sessions', 38 'django.contrib.messages', 39 'django.contrib.staticfiles', 40 'bot', 41 'gunicorn', 42 ] 43 44 CHATTERBOT = { 45 'name':'FLbot', 46 'storage_adapter':'mongodbn.MongoDatabaseAdapter', 47 'logic_adapters':[ 48 #{ 49 # "import_path": "chatterbot.logic.BestMatch", 50 # "statement_comparison_function": "chatterbot.comparisons.levenshtein_distance", 51 # "response_selection_method": "chatterbot.response_selection.get_first_response" 52 #}, 53 { 54 'import_path': 'logic.MyLogicAdapter' 55 }, 56 #{ 57 # 'import_path': 'chatterbot.logic.LowConfidenceAdapter', 58 # 'threshold': 0.65, 59 # 'default_response': '我还不知道=?=' 60 #}, 61 'chatterbot.logic.MathematicalEvaluation', 62 ], 63 'database':'chatterbot-1w', 64 'database_uri':"mongodb://192.168.2.128:27017/", 65 'read_only':True, 66 'django_app_name':"FLchatterbot", 67 } 68 69 MIDDLEWARE = [ 70 'django.middleware.security.SecurityMiddleware', 71 'django.contrib.sessions.middleware.SessionMiddleware', 72 'django.middleware.common.CommonMiddleware', 73 #'django.middleware.csrf.CsrfViewMiddleware', 74 'django.contrib.auth.middleware.AuthenticationMiddleware', 75 'django.contrib.messages.middleware.MessageMiddleware', 76 'django.middleware.clickjacking.XFrameOptionsMiddleware', 77 ] 78 79 ROOT_URLCONF = 'FLchatterbot.urls' 80 81 82 TEMPLATES = [ 83 { 84 'BACKEND': 'django.template.backends.django.DjangoTemplates', 85 'DIRS': [], 86 'APP_DIRS': True, 87 'OPTIONS': { 88 'context_processors': [ 89 'django.template.context_processors.debug', 90 'django.template.context_processors.request', 91 'django.contrib.auth.context_processors.auth', 92 'django.contrib.messages.context_processors.messages', 93 ], 94 }, 95 }, 96 ] 97 98 WSGI_APPLICATION = 'FLchatterbot.wsgi.application' 99 100 101 # Database 102 # https://docs.djangoproject.com/en/1.11/ref/settings/#databases 103 104 DATABASES = { 105 'default': { 106 'ENGINE': 'django.db.backends.sqlite3', 107 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 108 } 109 } 110 111 112 # Password validation 113 # https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 114 115 AUTH_PASSWORD_VALIDATORS = [ 116 { 117 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 118 }, 119 { 120 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 121 }, 122 { 123 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 124 }, 125 { 126 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 127 }, 128 ] 129 130 131 # Internationalization 132 # https://docs.djangoproject.com/en/1.11/topics/i18n/ 133 134 LANGUAGE_CODE = 'en-us' 135 136 TIME_ZONE = 'UTC' 137 138 USE_I18N = True 139 140 USE_L10N = True 141 142 USE_TZ = True 143 144 145 # Static files (CSS, JavaScript, Images) 146 # https://docs.djangoproject.com/en/1.11/howto/static-files/ 147 148 STATIC_URL = '/static/' 149 STATICFILES_DIRS = ( 150 os.path.join( 151 os.path.dirname(__file__), 152 'static', 153 ), 154 )
下面是源码"/usr/local/lib/python3.5/site-packages/django/urls/conf.py"
1 """Functions for use in URLsconfs.""" 2 from functools import partial 3 from importlib import import_module 4 5 from django.core.exceptions import ImproperlyConfigured 6 7 from .resolvers import ( 8 LocalePrefixPattern, RegexPattern, RoutePattern, URLPattern, URLResolver, 9 ) 10 11 12 def include(arg, namespace=None): 13 app_name = None 14 if isinstance(arg, tuple): 15 # Callable returning a namespace hint. 16 try: 17 urlconf_module, app_name = arg 18 except ValueError: 19 if namespace: 20 raise ImproperlyConfigured( 21 'Cannot override the namespace for a dynamic module that ' 22 'provides a namespace.' 23 ) 24 raise ImproperlyConfigured( 25 'Passing a %d-tuple to include() is not supported. Pass a ' 26 '2-tuple containing the list of patterns and app_name, and ' 27 'provide the namespace argument to include() instead.' % len(arg) 28 ) 29 else: 30 # No namespace hint - use manually provided namespace. 31 urlconf_module = arg 32 33 if isinstance(urlconf_module, str): 34 urlconf_module = import_module(urlconf_module) 35 patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module) 36 app_name = getattr(urlconf_module, 'app_name', app_name) 37 if namespace and not app_name: 38 raise ImproperlyConfigured( 39 'Specifying a namespace in include() without providing an app_name ' 40 'is not supported. Set the app_name attribute in the included ' 41 'module, or pass a 2-tuple containing the list of patterns and ' 42 'app_name instead.', 43 ) 44 namespace = namespace or app_name 45 # Make sure the patterns can be iterated through (without this, some 46 # testcases will break). 47 if isinstance(patterns, (list, tuple)): 48 for url_pattern in patterns: 49 pattern = getattr(url_pattern, 'pattern', None) 50 if isinstance(pattern, LocalePrefixPattern): 51 raise ImproperlyConfigured( 52 'Using i18n_patterns in an included URLconf is not allowed.' 53 ) 54 return (urlconf_module, app_name, namespace) 55 56 57 def _path(route, view, kwargs=None, name=None, Pattern=None): 58 if isinstance(view, (list, tuple)): 59 # For include(...) processing. 60 pattern = Pattern(route, is_endpoint=False) 61 urlconf_module, app_name, namespace = view 62 return URLResolver( 63 pattern, 64 urlconf_module, 65 kwargs, 66 app_name=app_name, 67 namespace=namespace, 68 ) 69 elif callable(view): 70 pattern = Pattern(route, name=name, is_endpoint=True) 71 return URLPattern(pattern, view, kwargs, name) 72 else: 73 raise TypeError('view must be a callable or a list/tuple in the case of include().') 74 75 76 path = partial(_path, Pattern=RoutePattern) 77 re_path = partial(_path, Pattern=RegexPattern)
解决不掉了,在线等急急急.
@DanBrown: url(r'^api/chatterbot/', include(chatterbot_urls, namespace='chatterbot')),这里应该有问题,namespace是什么参数,去掉试试
@DanBrown: 一般都是这样来写的啊url(r'^polls/', include('polls.urls')),
@Dicky_Zhang:
1 [root@localhost FLchatterbot]# python3 manage.py migrate 2 System check identified some issues: 3 4 WARNINGS: 5 ?: (urls.W005) URL namespace 'admin' isn't unique. You may not be able to reverse all URLs in this namespace 6 Operations to perform: 7 Apply all migrations: admin, auth, contenttypes, django_chatterbot, sessions 8 Running migrations: 9 No migrations to apply.
url页面
1 """FLchatterbot URL Configuration 2 3 The `urlpatterns` list routes URLs to views. For more information please see: 4 https://docs.djangoproject.com/en/2.0/topics/http/urls/ 5 Examples: 6 Function views 7 1. Add an import: from my_app import views 8 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 Class-based views 10 1. Add an import: from other_app.views import Home 11 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 Including another URLconf 13 1. Import the include() function: from django.urls import include, path 14 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 """ 16 from django.contrib import admin 17 from django.urls import path 18 from django.conf.urls import url, include 19 from chatterbot.ext.django_chatterbot import urls as chatterbot_urls 20 from bot import views 21 22 urlpatterns = [ 23 path('admin/', admin.site.urls), 24 url(r'^$', views.ChatterBotAppView.as_view(), name='main'), 25 url(r'^admin/', admin.site.urls, name='admin'), 26 url(r'^api/chatterbot/',include(chatterbot_urls)),
是django版本问题我换到老版本好使了。