开发者社区> 问答> 正文

在Django框架中使用python运行服务器时出错

我是编程的初学者,我的第一个项目是使用Django框架作为后台使用python创建网站,但是尝试运行服务器。我收到以下错误。那么有人可以解释吗?

(myvenv) C:\Users\Rohan Jain\venvi>python manage.py runserver
    Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001FACC183378>
Traceback (most recent call last):
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-  packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\Rohan Jain\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module

展开
收起
祖安文状元 2020-02-22 18:15:53 773 0
1 条回答
写回答
取消 提交回答
  • from django.conf.urls import include, url
                                 ^^^^^^^
    urlpatterns = [
    # ... snip ...
    url(r'^community/', include('django_website.aggregator.urls')),
    url(r'^contact/', include('django_website.contact.urls')),
    # ... snip ...
    ]
    
    

    因此,对于一些解释:

    当您尝试运行程序时,问题在于单词“ include”没有在任何地方定义。为了解决这种情况,您需要定义该单词,并且由于这是django.conf.urls中的一个函数,就像从文件开头导入它一样简单。

    希望对您有所帮助,这里有一些文档可能会帮助您了解有关django的更多信息

    https://docs.djangoproject.com/zh-CN/1.11/topics/http/urls/

    2020-02-22 18:16:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS块储存产品全面解析 立即下载