将Django网站运行到服务器时,“模块"对象不可迭代 [英] 'module' object is not iterable when running django website to the server
问题描述
我想将django网站运行到他们的服务器上,所以我打开cmd并转到manage.py目录:
i wanted to run my django website to their server so i open cmd and go to manage.py directory :
C:\Users\computer house>cd desktop/newproject
然后我输入以下代码:
python manage.py runserver
但我收到此错误:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03BE5A08>
Traceback (most recent call last):
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 542, 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 "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 364, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\base.py", line 351, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\registry.py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\urls.py", line 67, in _load_all_namespaces
namespaces.extend(_load_all_namespaces(pattern, current))
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\computer house\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py", line 549, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'videos.urls' from 'C:\\Users\\computer house\\Desktop\\newproject\\videos\\urls.py'>' 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.
这是我的videso \ url.py代码:
and this is my videso\url.py code :
from django.urls import path
from videos import views
urlpatternes = [
path('', views.index , name = 'index'),
]
此错误模块对象不可迭代"是什么意思?
what does this error 'module object is not iterable ' mean ?
推荐答案
此错误似乎是由于您没有/videos/urls.py
文件或其中没有任何有效文件网址格式.
This error seems like either you don't have a /videos/urls.py
file or it doesn't contain any valid url patterns.
第1步.在 videos
文件夹中创建一个 urls.py
(如果有,则无需创建)
第2步.将以下代码添加到/videos/urls.py
Step 1. Create a urls.py
inside your videos
folder(if there is a one, no need to create)
Step 2. add the following code to /videos/urls.py
urlpatterns = []
空 urlpatterns
被视为Django中的有效
模式
Empty urlpatterns
considered as a valid
patter in Django
这篇关于将Django网站运行到服务器时,“模块"对象不可迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!