python3 manage.py runserver错误

时间:2018-04-08 09:58:12

标签: python django python-3.x

当我尝试在我的电脑上启动(python3 manage.py runserver)我的django2.0 webapp时,我有这样的信息:

执行系统检查......

.wrapper在0x7fc889c36510>启动的线程中未处理的异常 回溯(最近一次调用最后一次):

文件“/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py”,第538行,在url_patterns中     ITER(图案) TypeError:'module'对象不可迭代

在处理上述异常期间,发生了另一个异常:

追踪(最近一次通话):   在包装器中输入文件“/home/neo/.local/lib/python3.5/site-packages/django/utils/autoreload.py”,第225行     fn(* args,** kwargs)

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/management/commands/runserver.py”,第120行,在inner_run中     self.check(display_num_errors = TRUE)

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/management/base.py”,第364行,正在检查中     include_deployment_checks = include_deployment_checks,

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/management/base.py”,第351行,在_run_checks中     return checks.run_checks(** kwargs)

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/checks/registry.py”,第73行,在run_checks中     new_errors = check(app_configs = app_configs)

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py”,第13行,在check_url_config中     return check_resolver(resolver)

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py”,第23行,在check_resolver中     return check_method()

文件“/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py”,第398行,正在检查中     warnings.extend(check_resolver(图案))

文件“/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py”,第23行,在check_resolver中     return check_method()

文件“/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py”,第397行,正在检查中     对于self.url_patterns中的模式:

文件“/home/neo/.local/lib/python3.5/site-packages/django/utils/functional.py”,第36行,获取     res = instance。 dict [self.name] = self.func(instance)

文件“/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py”,第545行,在url_patterns中     raise ImproperlyConfigured(msg.format(name = self.urlconf_name)) django.core.exceptions.ImproperlyConfigured:包含的URLconf''似乎没有任何模式。如果您在文件中看到有效模式,则问题可能是由循环导入引起的。

我的应用代码:

(/ Django的实例/ mysite的):

(Setting.py)

INSTALLED_APPS = [
'webexample',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

(urls.py)

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path('webexample/', include('webexample.urls')),
]

(/ Django的实例/ mysite的/ webexample):

(urls.py)

from django.urls import path
from . import views

urlpatterns = [
path('', views.index, name='index'),
]

(views.py)

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
return HttpResponse("<h3>Hello, world!</h3>")

ubuntu 16.04 django 2.0.4 python 3.5 点8.1.1

问题可能是什么原因?

5 个答案:

答案 0 :(得分:0)

  

The order of INSTALLED_APPS is significant!

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'webexample',
]

答案 1 :(得分:0)

要将您的应用添加到主项目文件夹中的settings.py中,您需要编写以下内容:

INSTALLED_APPS = [
    '*AppName*.apps.*Class*',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    ]

如果必须从您的App文件夹中的 apps.py 获取您的应用,类,则AppName将为名称。 这里的AppName似乎是 webexample ,并且 apps.py 中唯一类的名称将替换该类。 我希望这能解决您的查询。

答案 2 :(得分:0)

如果您有rest框架或mysql,则需要在已安装的应用程序中提及它。

WM_CLOSE

答案 3 :(得分:0)

尝试更改urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('webexample.urls')),
]

答案 4 :(得分:0)

项目 urls.py 应该像这样更改:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('webexample.urls')),
]

View.py 应该像这样更改:

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("<h3>Hello, world!</h3>")
相关问题