简体   繁体   中英

python3 manage.py runserver error

When I try to start (python3 manage.py runserver) my django2.0 webapp on my PC I have this message:

Performing system checks...

Unhandled exception in thread started by .wrapper at 0x7fc889c36510> Traceback (most recent call last):

File "/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 538, in url_patterns iter(patterns) TypeError: 'module' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/neo/.local/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs)

File "/home/neo/.local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run self.check(display_num_errors=True)

File "/home/neo/.local/lib/python3.5/site-packages/django/core/management/base.py", line 364, in check include_deployment_checks=include_deployment_checks,

File "/home/neo/.local/lib/python3.5/site-packages/django/core/management/base.py", line 351, in _run_checks return checks.run_checks(**kwargs)

File "/home/neo/.local/lib/python3.5/site-packages/django/core/checks/registry.py", line 73, in run_checks new_errors = check(app_configs=app_configs)

File "/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver)

File "/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method()

File "/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 398, in check warnings.extend(check_resolver(pattern))

File "/home/neo/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method()

File "/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 397, in check for pattern in self.url_patterns:

File "/home/neo/.local/lib/python3.5/site-packages/django/utils/functional.py", line 36, in get res = instance. dict [self.name] = self.func(instance)

File "/home/neo/.local/lib/python3.5/site-packages/django/urls/resolvers.py", line 545, in url_patterns raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) django.core.exceptions.ImproperlyConfigured: The included URLconf '' 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.

my app's code :

(/django-examples/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-examples/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 pip 8.1.1

What can be a reason of problem?

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',
]

To add your apps to settings.py in the main project folder, you need to write the following:

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

The AppName will be the name if your app, Class must be obtained from apps.py in your App folder. Here the AppName seems to be webexample , and the name of the only class in its apps.py will replace the class. I hope this will resolve your query.

If you have rest framework or mysql, then you need to mention it in the installed apps.

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

try changing urls.py

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

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

Project urls.py should be changed like this:

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

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

View.py should be changed like this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM